stc

a simple time card webapp
git clone _git@git.brennen.work:stc.git
Log | Files | Refs | README

commit 2f1587ca96eed201053e954dca8b32168d2d09f0
parent 21a59380f05d1a0829e0d9681a266531d618bfce
Author: Brennen T. Mazur <brennen@madis.cool>
Date:   Thu, 19 Jan 2023 08:15:02 -0700

Merge branch 'backend' of git.brennen.work:stc into backend

Diffstat:
Mmodels.py | 56++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 20 deletions(-)

diff --git a/models.py b/models.py @@ -4,37 +4,53 @@ # fixed datetime import datetime -from flask import Flask, jsonify, request - +import uuid +from flask import Flask, jsonify, request, redirect, session from fastapi.encoders import jsonable_encoder +from passlib.hash import pbkdf2_sha256 # Replace with Brennen's hash when he finds it from typing import List, Optional -from pydantic import BaseModel, Field, ValidationError, validator +from pydantic import Field, ValidationError, validator +from app import db class Users: + def start_session(self, user): + del user['password'] + session['logged_in'] = True + session['user'] = user + return jsonify(user), 200 + def signup(self): print(request.form) users = { - '_id': '', - 'username': '', - 'password': '', - 'role': '', - 'location': '', - 'phone': '', - 'email': '', - 'active': '', - 'pay_period': '', - 'pay_value': '', + '_id': uuid.uuid4().hex, + 'username': request.form.get('Username'), + 'password': request.form.get('Password'), + 'role': request.form.get('Role'), + 'location': request.form.get('Primary Location'), + 'phone': request.form.get('Phone Number'), + 'email': request.form.get('Email'), + 'pay_period': request.form.get('Pay Period'), + 'pay_value': request.form.get('Pay Value'), } + # users['password'] = pbkdf2_sha256.encrypt(users['password']) + return jsonify(users), 200 - def login(self): - user = { - 'username': '', - 'password': '', - 'confirm_password': '', - } + def signout(self): + session.clear() + return redirect('/login') + + # def login(self): + # users = db.users.find_one({ + # 'email': request.form.get('email') + # }) + + # if users and pbkdf2_sha256.verify(request.form.get('password'), users['password']): + # return self.start_session(users) + + # return jsonify({ 'error': 'Invalid login' }), 401 @validator('username') def username_alphanumeric(cls, v): @@ -57,7 +73,7 @@ class Time: def clockout(self): clockout = { '_id': int, - # 'clock_out': Optional[datetime.now], + 'clock_out': Optional[datetime.datetime.utcnow], 'date': Optional[datetime.date], 'project': str, 'note': Optional[str],