From 88a00e3a4bb80b4bf1cdefaeafcfea73ebf93c7e Mon Sep 17 00:00:00 2001 From: ydb5755 Date: Wed, 4 Sep 2024 21:43:20 +0300 Subject: [PATCH] login and register --- README.md | 1 + app/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 1808 bytes app/__pycache__/config.cpython-310.pyc | Bin 0 -> 750 bytes app/config.py | 3 +- app/main/__pycache__/__init__.cpython-310.pyc | Bin 0 -> 344 bytes app/main/__pycache__/routes.cpython-310.pyc | Bin 0 -> 778 bytes app/main/templates/base.html | 15 ++-- .../__pycache__/__init__.cpython-310.pyc | Bin 0 -> 348 bytes app/users/__pycache__/forms.cpython-310.pyc | Bin 0 -> 1448 bytes app/users/__pycache__/models.cpython-310.pyc | Bin 0 -> 1666 bytes app/users/__pycache__/routes.cpython-310.pyc | Bin 0 -> 2406 bytes app/users/forms.py | 28 ++++++ app/users/routes.py | 54 +++++++++++- app/users/templates/login.html | 35 ++++++++ app/users/templates/register_user.html | 81 ++++++++++++++++++ app/users/templates/user_page.html | 38 ++++++++ 16 files changed, 243 insertions(+), 12 deletions(-) create mode 100644 app/__pycache__/__init__.cpython-310.pyc create mode 100644 app/__pycache__/config.cpython-310.pyc create mode 100644 app/main/__pycache__/__init__.cpython-310.pyc create mode 100644 app/main/__pycache__/routes.cpython-310.pyc create mode 100644 app/users/__pycache__/__init__.cpython-310.pyc create mode 100644 app/users/__pycache__/forms.cpython-310.pyc create mode 100644 app/users/__pycache__/models.cpython-310.pyc create mode 100644 app/users/__pycache__/routes.cpython-310.pyc create mode 100644 app/users/templates/login.html create mode 100644 app/users/templates/register_user.html create mode 100644 app/users/templates/user_page.html diff --git a/README.md b/README.md index 9f7986b..109643d 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # Pilzno +Building out the pilzno crm \ No newline at end of file diff --git a/app/__pycache__/__init__.cpython-310.pyc b/app/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3c0c9a4449d8fe3e84bc62ae24c28940a3c7db7b GIT binary patch literal 1808 zcmd1j<>g{vU|^`JyOHL{&cN^(#6iZa3=9ko3=9m#>lhdqQW#Pga~N_NqZo6UqL^}- zqnH^%VoW(KxvWvFU^a6OTP}MPJDAOq!;#Aw#R+D!=5Xb5M{$GMY&kr+yivShHhT_V zE`Jn1n9Y$RkSiD^2xfEU2;~Y#3FnGLi7+yxayBzWiKcQlGen7{@-{O>iKp^6Gek+G zvZipQvS&%AvS&%9aQ8Atv83>%@U}2SNvH4yGidU^1o=dh`4+2NPGWKPEsmnpl+2>k z>8T*iEWU}EIhu^OI0B0DD=OVGD>RvIal2*aq>qnWXmDTSkiJ6=46C51CbB3H5&ln7W-xN@X&rE6Ij8EP07$kZ@{%muT+ z?yg~2Ae+LykP#9+&5X6IH4G)JX-vTkntXm$JgG%R`9(ST>3SsGbc?;TIJGD~GvyWwh*2cMz`(GQ;g_y{ zMt*Lper0BHQGRNUk-kf6adt_5fqp<{PE}sMequp^etdjpUS>&ryk0@&EzX?$#FTiD z0V*Ija4;}1@G!A3vM{nRRmmn7r6!i7#wQjO=-K4tCnx3<+v&m8S8;=M73<}Il9eXo zEmkmBlkpZyZenKMFGhWoBm(j=$fv;|TX>*J1QfB&jKK_=Onz0oAYFPOw-+R)r)n}4 zfm9c z-{Odm&r8frjgP;@mJH5Bx46@a@^jLgJkqoxNTCT)=+En#4J5 ja`RJ4b5iXBO4PNBM1sH@-PDcde7AE literal 0 HcmV?d00001 diff --git a/app/__pycache__/config.cpython-310.pyc b/app/__pycache__/config.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0ea1947465c234b1416707d23d16964a414a5e7b GIT binary patch literal 750 zcmd1j<>g{vU|?{bearANaaP^IhcX14HbaD)KjSmg-j1La<@eFaj#TD%89ON1j z@9i3y3^EcK!=2~Dz`&5o5XG3n5XF?rynrQzaUo+AE11Q!kTHrag*l2ng(Zq3g*A#Z zg)NFJg)NFZg*}P~tb$`9V-zo##kr6%iZ6vLm_d{K7MpW^URq{)5y*}r76t}}Om8Lz zhLB8#)U&cx5=E&gnZ;K6`Z@W@i8&eh#U)l|#^#p#2AYgj0*M6$ddaCdsYR9XC5gq^ z#kV+veM17`LxWv|Zt;Sd0gl1J;r>A`ewzHZIO5~;5_41I<8N`r$LHp!l;(igJn`{` zrHMIE8Mb7wTW&F@rU2B}0)2hz%lsY3pa?=cejcW)>Iar{);xyQCIpm*f}d2V~|{ z<>l)q78K}1e4*wxj9iQ?NRW$>j}fd!ljRmue(^1qtm6E< oB9I2KD8g0g{vU|^6by^+Sk$iVOz#6iaF3=9ko3=9m#dJGH(5FF_`0GT!2J$|+4PD9X$$xy6#3 zn3;Ervm`aQASbaTwfGiWaYO2lkFC3T25kdb`cW;1H&zj`1riU+|>B^B4#i*v7kT?WPTAR z0|UcKh9X`D1_<%XNIxS#H&wqfv$!ZfHOENbCAB!aB)>pEATy^bFJC{gpaASJ{rLFI pyv&mLc)fzkTO2mI`6;D2sdkK@kP%>DVBle3VPay0K(;>uYye4ZUEBZw literal 0 HcmV?d00001 diff --git a/app/main/__pycache__/routes.cpython-310.pyc b/app/main/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..be8b20e28d1e4ac1ab8144f6ece151cafc728270 GIT binary patch literal 778 zcmd1j<>g{vU|;>hKU;>_iW;>zWY;s(pH=J4e5M)BtIMe*hG zNAc$hLVJPg`$LVg`#J6Q7n}bc;1DC$Tu=7JE@@VQFe{i6+Y}zMTB@%)EGzKxR>D$}KJk zzqB~D=oU|MX;D#XUP(Nd$DNa(o?i;#XfoXrPR>Y8&W0h zlvt9ADz3?Riz6kmB()?nH`T9-Q$Hg=H?<%!JvABRA!N+Nz`)=PiUJM>28I%b6vk%8 zU~)Z*-t`~v-e z%$%yceEr0N0)0?`=@;dfmZTQz6;$5hfSJh$vJqr82Xm1y0|SGm#4YB;f`THD&@GO{ zf&x8|&LU9yxFrDMg2JO%FE>9WHK(|Ug@J(q60q4|R~4~=+{6wdK)xvA1j%!Q0zNw) z9JocGWLU%vQosWuctHvT%TtT8t5QqT^@>xION%l~DvLnQD&hyJ5CExQ$}hgf3U)o% xkqECtSVAB*95%W6DWy57c8nk|i7+rQ@G$T&@-WIUNiYg9@-T8Ra {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} diff --git a/app/users/__pycache__/__init__.cpython-310.pyc b/app/users/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9125a02771ffec5cf73154347b459fa159d3a998 GIT binary patch literal 348 zcmd1j<>g{vU|>itxsk@f$iVOz#6iaF3=9ko3=9m#dJGH(5FF_`0GT!2J$|+4PD9X$$xy4#q zoLW?Ti?bv(w;(66B(?Y!TX9KZNoH~tn?6`dllc}uOfo(#KPM%%=oT+T35?5CT9gxC zP?VaMS)s{zi>)ZXv?R6IPm}EyYg$fXadr_C0|Ub?j`;Yz#N5>Q_#$Qymou@TKo4v| z5hnu!!%BuCUIqpT@yl30BR@A)zcRD9C_gpFNZ%#3IJ+djKtCWerz$UBKe3g{vU|?`scq7f3m4V?gh=Yt-7#J8F7#J9e=P)oZq%fo~<}l!jQs|%Gk^t zCE?DH!kNO=!jQrR=1Zn<2Qz5$yac&hlkpa(TTWtewp)Htt|t2}?%JW)6gNiwDFEN-ZqSEJ{te#SP*)=H%p;r>1DK-r{jdEJ=h*@`oknWTqsRWaj6& z78T_e-QxBu%}q)z3QEjNPrb$NT3DKx6Ow<673^3|##=0*#i>P_jJJ4_ON)w9^Gf1N zi&Kk|L7qj%@QAWuU|>jPh+<4(h+;}*PGL-CX=X@gOkwI}iegP=OJPRhv!`;TurxD9 zai(&mur@PBai_2aGib8k;`GT+&&&gbV38mL1H($jTU=!jH|G}>-{OFUTordvYHljX z=?b~2w^+fN{4{xPam2^xCFZ8a$KT?LkI&6dDa`?~dE(SoLP|{A}>}7(Q z#GT5M!qv z9%L3g9w9NR2oh6bU|OkHChrlg?#DW4naQf2A%}+_qDJ~KMnZXUQA_tUg{vU|?8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 diff --git a/app/users/__pycache__/routes.cpython-310.pyc b/app/users/__pycache__/routes.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0bae6dacfd261ff1bf2c1a71f51ab80d5503283c GIT binary patch literal 2406 zcmd1j<>g{vU|`t4_(s|*P6md@APzESWnf@%U|?V<{=~q*kiw9{n8T3E7{$m4Vl(A1 zBoyVhJryEz)GV#p#ou zo|)&CUzB@GASg9Gv$!O+2qXm((PX{FUzD1cl3EmBlA2qPlUR~^i=!wtC9^0sx#Sjm zX;DsmT7JAkRZF69WSS3j+g#GblCKFfcHbFqAN6F*P%m zFw`(KGiEat^OrD}u%s}8Vj`HKgf)vTi@k;+g{hZu0mnjyTE-I26y_Sn6qa75U~)Z*-t`~v-e%$%yceEr0N0&uVt>lfvh zmZTQz6;$5h1e*hLAIK@iJPZsBLd-mjLX0eoOpI**i)2COGU`{c>4PIplj#<-yKBfT zmH_|Y5KYEg?768W8Tl#2$;fy&k*UXX+eh~NgvvLqIz7vEw|PlYB; z<|0jy94J}d;skjCoC(3{6GF&xA4KNGr7dA+tr3ETT*ub9QVB}#eG6Ff8PrnFS zih>I`6t{y)AW&`wyFCl)c5tR(T*y$QU&2(wkj0$EQp1qN3MSdISW4Jy7_vCBSehAA z7*m*fSwW>x7S{sq8pef;j0`25SzHTv7J~fGo5I`-65%W1Pho-hzeFH~wT1zdL4p}H z+5Ny#ugQ9g3tX(k=OyN*-r~$jEG_{vi$E!%NEZ}UkP@P#vLLleJQ$o#!O2tsRz0Mq zKtila2*s=5G+Lwq3QEBuP_PtfgTfP>;EX{m9S~sxBEWVDf>`Q0QqgArc&V%JJa7fc$A=BJeAq}qXM#bQuI j@i6d!^PUW&1fu{W4 literal 0 HcmV?d00001 diff --git a/app/users/forms.py b/app/users/forms.py index e69de29..b7139ca 100644 --- a/app/users/forms.py +++ b/app/users/forms.py @@ -0,0 +1,28 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, \ + EmailField, \ + PasswordField, \ + SubmitField, \ + SelectField, \ + BooleanField,\ + DateField +from flask_wtf.file import FileField, FileRequired, FileAllowed +from wtforms.validators import DataRequired, ValidationError, NumberRange, EqualTo, Email +from app.users.models import User +from flask_login import current_user +# import logging +# logging.basicConfig(filename='logs.log', encoding='utf-8', level=logging.DEBUG) + +class LoginForm(FlaskForm): + email = EmailField('Email', validators=[DataRequired()]) + password = PasswordField('Password', validators=[DataRequired()]) + remember = BooleanField('Remember me') + submit = SubmitField('Login') + +class RegisterUserForm(FlaskForm): + email = StringField('Email', validators=[DataRequired(), Email()]) + first_name = StringField('First Name', validators=[DataRequired()]) + last_name = StringField('Last Name', validators=[DataRequired()]) + password = StringField('Password', validators=[DataRequired()]) + confirm_password = StringField('Confirm Password', validators=[DataRequired(), EqualTo('password', message='Passwords must match')]) + submit = SubmitField('Register') \ No newline at end of file diff --git a/app/users/routes.py b/app/users/routes.py index 80205b7..2ba8714 100644 --- a/app/users/routes.py +++ b/app/users/routes.py @@ -1,7 +1,7 @@ from app import db from app.users import users from app.users.models import User -# from forms import LoginForm, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm +from app.users.forms import LoginForm, RegisterUserForm#, RequestResetForm, ResetPasswordForm, EditUserForm, AddUserForm from flask import render_template, redirect, url_for, flash, request from flask_login import login_required, login_user, current_user, logout_user from werkzeug.security import check_password_hash, generate_password_hash @@ -13,6 +13,52 @@ import os @users.route('/user_page/') @login_required -def user_page(user_id): - - return render_template('user_page.html') \ No newline at end of file +def user_page(user_id): + if not int(current_user.id) == int(user_id): + return redirect(url_for('main.dashboard')) + user = User.query.filter_by(id=user_id).first() + return render_template('user_page.html', + user=user) + + +@users.route('/') +@users.route('/login', methods=('GET', 'POST')) +def login(): + if current_user.is_authenticated: + return redirect(url_for('main.dashboard')) + form = LoginForm() + if form.validate_on_submit(): + user = User.query.filter_by(email=form.email.data).first() + if not user or not check_password_hash(user.password, form.password.data): + flash('Please check your login details and try again.', 'bad') + return redirect(url_for('users.login')) + login_user(user, remember=form.remember.data) + flash("You've been logged in successfully!", 'good') + next_page = request.args.get('next') + return redirect(next_page) if next_page else redirect(url_for('main.homepage')) + return render_template('login.html', + form=form) + +@users.route('/logout') +@login_required +def logout(): + logout_user() + flash('You\'ve been successfully logged out!') + return redirect(url_for('main.homepage')) + +@users.route('/register_user', methods=('GET', 'POST')) +def register_user(): + form = RegisterUserForm() + if form.validate_on_submit(): + user = User( + first_name=form.first_name.data, + last_name=form.last_name.data, + email=form.email.data, + password=generate_password_hash(form.password.data), + user_type="User", + ) + db.session.add(user) + db.session.commit() + flash('Succesfully Registered!') + return redirect(url_for('main.homepage')) + return render_template('register_user.html', form=form) \ No newline at end of file diff --git a/app/users/templates/login.html b/app/users/templates/login.html new file mode 100644 index 0000000..68bf1f0 --- /dev/null +++ b/app/users/templates/login.html @@ -0,0 +1,35 @@ +{% extends 'base.html' %} +{% block title %}Login{% endblock title %} +{% block content %} +
+
+
+
+
+

Login User

+
+ {{ form.hidden_tag() }} + +
+ {{ form.email.label(class="form-label") }} + {{ form.email(class="form-control") }} +
+ +
+ {{ form.password.label(class="form-label") }} + {{ form.password(class="form-control") }} +
+ +
+ {{ form.remember(class="form-check-input") }} + +
+ + {{ form.submit(class='btn btn-primary') }} +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/users/templates/register_user.html b/app/users/templates/register_user.html new file mode 100644 index 0000000..3a006f6 --- /dev/null +++ b/app/users/templates/register_user.html @@ -0,0 +1,81 @@ +{% extends 'base.html' %} +{% block title %}User Access{% endblock title %} +{% block content %} +
+
+
+
+
+

Register

+
+ {{ form.hidden_tag() }} + +
+ {{ form.first_name.label(class="form-label") }} + {{ form.first_name(class="form-control") }} + {% if form.first_name.errors %} +
    + {% for error in form.first_name.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.last_name.label(class="form-label") }} + {{ form.last_name(class="form-control") }} + {% if form.last_name.errors %} +
    + {% for error in form.last_name.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.email.label(class="form-label") }} + {{ form.email(class="form-control") }} + {% if form.email.errors %} +
    + {% for error in form.email.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.password.label(class="form-label") }} + {{ form.password(class="form-control") }} + {% if form.password.errors %} +
    + {% for error in form.password.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ +
+ {{ form.confirm_password.label(class="form-label") }} + {{ form.confirm_password(class="form-control") }} + {% if form.confirm_password.errors %} +
    + {% for error in form.confirm_password.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ + + {{ form.submit(class='btn btn-primary') }} +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/users/templates/user_page.html b/app/users/templates/user_page.html new file mode 100644 index 0000000..384348b --- /dev/null +++ b/app/users/templates/user_page.html @@ -0,0 +1,38 @@ +{% extends 'base.html' %} +{% block title %}User Page{% endblock title %} +{% block content %} +
+
+
+

Welcome, {{ user.first_name }} {{ user.last_name }}

+
+
+
+ +
+
+ {% if user_reports %} +

Downloadable Files:

+ + + + + + + + + + + + + + +
Report TypeNumber of RowsTime CreatedRange StartRange EndDownloadDelete
+ {% else %} +

No reports available.

+ {% endif %} +
+
+
+ +{% endblock %} \ No newline at end of file