From 3de146fb7615cf05f6dcd1f980ff00b97373f90a Mon Sep 17 00:00:00 2001 From: victor <2585414795@qq.com> Date: Sun, 17 Feb 2019 16:59:22 +0800 Subject: [PATCH] update email functions, register template --- .idea/dataSources.local.xml | 10 + .idea/dataSources.xml | 14 + .idea/workspace.xml | 246 ++++++++++-------- __pycache__/config.cpython-35.pyc | Bin 1726 -> 1709 bytes app/__init__.py | 4 +- app/__pycache__/__init__.cpython-35.pyc | Bin 1175 -> 1049 bytes app/__pycache__/__init__.cpython-37.pyc | Bin 0 -> 1084 bytes app/__pycache__/mails.cpython-35.pyc | Bin 0 -> 912 bytes app/__pycache__/models.cpython-35.pyc | Bin 1625 -> 1625 bytes app/mails.py | 5 +- app/main/__pycache__/views.cpython-35.pyc | Bin 1201 -> 1347 bytes app/main/views.py | 20 +- app/models.py | 2 +- app/templates/base.html | 2 +- app/templates/macro/wtf.html | 33 ++- app/templates/mail/new_user.html | 10 + app/templates/register.html | 3 + config.py | 6 +- dev.db | Bin 4096 -> 6144 bytes migrations/README | 1 + migrations/__pycache__/env.cpython-35.pyc | Bin 0 -> 2430 bytes migrations/alembic.ini | 45 ++++ migrations/env.py | 90 +++++++ migrations/script.py.mako | 24 ++ .../versions/6e5a634d6369_create_tables.py | 38 +++ .../6e5a634d6369_create_tables.cpython-35.pyc | Bin 0 -> 1248 bytes 26 files changed, 429 insertions(+), 124 deletions(-) create mode 100644 .idea/dataSources.local.xml create mode 100644 .idea/dataSources.xml create mode 100644 app/__pycache__/__init__.cpython-37.pyc create mode 100644 app/__pycache__/mails.cpython-35.pyc create mode 100644 app/templates/mail/new_user.html create mode 100644 migrations/README create mode 100644 migrations/__pycache__/env.cpython-35.pyc create mode 100644 migrations/alembic.ini create mode 100644 migrations/env.py create mode 100644 migrations/script.py.mako create mode 100644 migrations/versions/6e5a634d6369_create_tables.py create mode 100644 migrations/versions/__pycache__/6e5a634d6369_create_tables.cpython-35.pyc diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml new file mode 100644 index 0000000..e3f1b6e --- /dev/null +++ b/.idea/dataSources.local.xml @@ -0,0 +1,10 @@ + + + + + + false + *: + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..5e1fe23 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,14 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/dev.db + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3c6721d..db3749e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,17 @@ - + + + + + + + + + + + + + + + + + + + @@ -186,18 +212,17 @@ - - - + - + @@ -211,156 +236,169 @@ - + - + - + - - + + - + + + + - - + + - + - - + + - + - - - - - + + - + - - + + - - + + + + + + - + - - + + + + + - + - - + + - + - + - - + + - + - - + + - + - + + + + - - + + - + - + - - + + + + + - + - - + + - + - - - - - + + - + - - + + - + - + - - + + - + - - + + + + + - + - - + + diff --git a/__pycache__/config.cpython-35.pyc b/__pycache__/config.cpython-35.pyc index 07e114a09048705c95561ba1d67367bbad9215a9..88576ef66a90950907e5dfaf431642038dc60415 100644 GIT binary patch delta 466 zcmdnTyOx(zjF*>-TOl)M^+ry4MvD|?hA19}RAz=O7KSWVh7@*&W=4i6UL+9?um~TL z2q#cvass2d+%0ZjM^B&lVAr59*PvURU`~L4P{=J|5OeZ8M%~Ge8MWEC7#J9exF(A* zJ+3ce1+m$H#4R4M^3Y({_~2llB6g5C2Z-PVOBR<{9 delta 430 zcmZ3>yN{PsjF*>7=u}3`nvI4! zA%%Hz0;4&5l!&jRr;p3zt&F-7x41#<_+ZzdFxQ}4oM29Xe^AKeM~vERoD2*MMVym` znI2DG&nW6v#0uiGfe3aG!2u+0@qo322D`=w2m9RODK1GY$xO~oEy>7FDdGXCf*1m4 zaZh$+mgN#+1VJ{YBBse!EMAj0F{_I6f|T%q2!0@Oi`B)|Db&44VDdX=RRIh$lvz5= z(KN7!xCV!K`T@0o%#a2VG9Ut7@8(A=OpMlOn%UCwi*gf7AbJHs+JtZ#Fj=0>o>5?O MJevfjyV}{*0KC0X!2kdN diff --git a/app/__init__.py b/app/__init__.py index 5fc39cf..1c8bd90 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,7 +6,7 @@ from flask_sqlalchemy import SQLAlchemy from flask_bootstrap import Bootstrap from flask_mail import Mail -from flask_login import LoginManager, LOGIN_MESSAGE_CATEGORY, LOGIN_MESSAGE +from flask_login import LoginManager from config import config moment = Moment() @@ -20,8 +20,6 @@ def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) - LOGIN_MESSAGE_CATEGORY = 'info' - LOGIN_MESSAGE = 'This page needs authentications' moment.init_app(app) db.init_app(app) diff --git a/app/__pycache__/__init__.cpython-35.pyc b/app/__pycache__/__init__.cpython-35.pyc index 68f3871c9bf71c59d5e9aa981e8cfb7233c76862..4af11019c81a95c520d48af947074774da750507 100644 GIT binary patch delta 412 zcmY+8y-EW?6ot>-iOK#&H$ND)3Z&Xb6s)Yoh$3hjyG00_%($#1o3Kf`q>3*PrjRs( z4`3%&KFPMeh%;*to#CGOhI6=_XKQV?cFSdZZN~Qj1HSO*7>du-Ox{+l-ZgQ6moRWK zbP>29!LS5^GQ?I6+YqH3b|9=AJP0R;3b+Yw;YsDItE_!QnR_#e;^a0=!bqe(WySs| zd5EJvZ3-0BtEa6Ce8?%C$agxwBya-*8$%ll12iW*I+z<+5{N64Z3-^fugSm*;Ho2$ z&fodPj_ez!WXc!g>eyEMvuY}$crq1fw>OxHaT+Jn)KP|C2%Mi@-6R}}jD_Q|Y_b+L zm`HU(1=7a^>fX|j@?giUgh28H+s z${xgj;nk~n_T*_jdJ_MGI1_`|`S{-VX1+J@-iP9Qr&05L_sj3`i|-uxf&UKE{DJQI zr_096r-_HqL*gU!K>`pvm;^`ygaJr$tbuSBvalg#$ej(@gLF3J8f0lhDiB2o2k*4L zdik~ejOX6*bQG(TNJS%==C$L~?&IFzq|@)Wx}8D0b=K*gK6#$|SKgbH+rz0kk4Hn= zdbahnbhnM?&smG^dxEfH5DY7hY)KE_a0m+%7m16N1-c--D&fMynsg|=EMTHTdRP_y zEejB~NxLR8`hK(6%dJ?QPha0Y8^`ndOuMctDaE`VEf-^{7V$7z#8Wl@X`E@JRuaX^ z%qZJscgf9;SeN|lExU0iFbX>?{f#nEQ6h65&1Pv)FH%QC_K`K{Ap6F8_ipJc$fGLl zkxe%9X(!LgtMNDFhn0b!K z3bO%MSqtz6^8nXa0Ju(F>U~6HgZe$x4lW@V)W)^_jHl&0AWpXsEU$q1y_bhOd@yF> z6fAGID5|oO=>!a`n`XRi*5P3>%JOcSrz0lot;6Gk=SN9*zt`J2*iZI$Uhf|qzj{+g z|M*pmL6Hx$(EzL9FdSGGtUXxe7k~;?_#Dsi44)VmW@XIKZS)nCYS@J}!^)y~Zct-x zR`$YEIZM`BGIz%bpjkFZtE|Y&OLZ@$l1Q^$J=Ol1-BAxP{i)>1M6zM_ zp&d!p6}6irc`8_vNYy@dFqDNziv9^3RJEJsS(T)dN$m(-n%bcK+UqaMp~LVx;;Iyh zXlfxNb_b`|IKGo4`X0%{$!YBmBugu%F0~FPmG=Pvx($lK^1$V($yN^Xdr<^@ed6c&R OLcEw8I5Zr5HO)VqxfD+T literal 0 HcmV?d00001 diff --git a/app/__pycache__/mails.cpython-35.pyc b/app/__pycache__/mails.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..28212396f948342d855578dbafbf296910f42328 GIT binary patch literal 912 zcmZ8fJ#W-N5Pj>X?@%^I5XTC2*cNwr*F(h4taY1K)kCswt~ zhSn&RK2ye2Qx22E6FMPBuD}2E(fDAp_k6Vf z_lCx<F4wA_EoZ8;=2Lw4#I}t~Y^A5lx`-xIB$`QSX5}JY*C}JB?P5b) zEp55RsU31KmG&cNyttB literal 0 HcmV?d00001 diff --git a/app/__pycache__/models.cpython-35.pyc b/app/__pycache__/models.cpython-35.pyc index 4c56eb39fc19c62cf0b1d6bbf1b0074347e52315..fedf7dcd9b8d50a5de611b983d460b2fbbacba9a 100644 GIT binary patch delta 18 Zcmcb~bCZWtjF*>-TO>1vXCr3-8vrX>1P%ZI delta 18 Zcmcb~bCZWtjF*=ynkh4edn0E68vrep1WNz_ diff --git a/app/mails.py b/app/mails.py index 6a4eacd..c0f1ff1 100644 --- a/app/mails.py +++ b/app/mails.py @@ -12,7 +12,7 @@ app = create_app(os.environ.get('FLASK_CONFIG') or 'default') -def async_mail(app, msg): +def async_mail(msg): with app.app_context(): mail.send(msg) @@ -20,6 +20,7 @@ def async_mail(app, msg): def send_mail(subject, recipients, msg_template, **kwargs): msg = Message(subject=subject, recipients=[recipients]) msg.html = render_template(msg_template + '.html', **kwargs) - th = Thread(target=async_mail, args=(app, msg)) + th = Thread(target=async_mail, args=(msg,)) th.start() + return th diff --git a/app/main/__pycache__/views.cpython-35.pyc b/app/main/__pycache__/views.cpython-35.pyc index 7d040cc1e7cf2f6ca2b53218ae2782f779b0b7a1..8607ea06240ff8762ef6aa9ceec361b197529337 100644 GIT binary patch literal 1347 zcmZ8h&2HO95T50aC{bc8IYFADKtcDC=ui_4Vk9YwB0$g-$iWTZ^iZOJKx@}BrCn0q zUB;1+oSbVOr0>y(DE8V*^9nh2hO`qSly*3?J3I5u&bPdsB=P%i%Riq60RO_ZCq(@T z4)Zq(j(-LcKrzS}C=YTEln=QNDu6ry#y#LZ$PiQrdDz(j$R4N&@~E>zkbO`C$OoO> z0~v!FLO$&52;>M<0(k;Vgs{8;ybpW;JO)05g$Eam@e%L@-T~^6@4%%SdVb-y1AKht zHU>U{qv`GktOTZk+tH%pLeH#FYgt&~`daW(i@9}Cqvhh($yE{v8)$a zv0i5cJbP7&bF;tRxUda9qP!FrJiUu@JIJ(Hl*S7E2_r2>I9iPVp@JAM0Nw(;0a!B9 z^*>-eSo*LGh#fSKP3z$jTSl!jPBPFdlFNSU&?kqLN0SyiMlA(qW3WS_4;pj`81;HQ z9(>-)!&V=4dHlBwY(hj??og68SZ9w30J9U|J>bzLkqAc!7d~T@JnsB=iCjo4#E<+s znkI*?-(X9tLW%7jHJ7xssCX)Caa@2TR@0lhkFCphUlp?C$n;rV%}jHw zN~?)?E<9_5-nhX@DY5yp#uo2s1->{gCz3b@g1VN{P}mo{{cHfH`M?D literal 1201 zcmZWoO>fgc5S{f$61z#0wzNnHp~3~_Kzv6Cfl%RADy3X3q{!)RQ#)Qe?5^7;qNnm_ z;OB7MBb<8W*b_5OQ>qeW$Fn=LGjC?z?sPg~%F@q&T!7zj=jWsT2ABSUg5#e-4j>uC z45S0G1JZ@q1?fTT0pkvE7jhq@53#@8dyqFkHX&}}9wYdWw?GCE2OvX;Ltw&(Yz=q= zcoTRFcmNXzE*aw?@HO}bs6*U_8@Kju};FzolP5HIvS+f}0ALXC`&vpg}v zwv^zh5=X{1E0vFqOJ)7zJkcjt4&7kZlSx|OH`M8*sAlg=CHs!`K53z>!^hVwvP~(> zNy)W!KkOY^@8IL`@QCuQeiZ2)E*+vUb=RrU$dR_3O}-Qd3-T)CS5$5GgT9wGrwT zBbl4HYK*^7L5!CG7XV)YGDf=k3C4lUh0LR&(>YG5fhLwUYiB%Upw7YI#AsZ=aGwRW zYe243r;dVVw>BFbCkFG$1E)JIVoGs0I8uNT)whugq^~WLx)%&g8?p{$>y($$-R!%B zhM69i4Pp;ksMq(C^@Dxes&IxyBE{k%O_Q|UBv&Hg^IelnMe%g;cn^D;@4n^y*0SoJ z;ET>mujgkyB#*SdpewdDOSC>K6<@TI%A5>{JtHL2rfOk>!^3I)o-B&*m{Ncs$9IL QQtGGl3{mvhj{DsI3zb$6y#N3J diff --git a/app/main/views.py b/app/main/views.py index abcf92e..9cb755e 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -4,7 +4,9 @@ from flask import render_template, redirect, url_for, flash from ..main import main from ..forms import signupForm -from app.models import User, db +from .. import db +from ..models import User +from ..mails import send_mail @main.route('/', methods=['GET', 'POST']) @@ -13,18 +15,18 @@ def index(): @main.route('/register', methods=['GET', 'POST']) -def user_register(): +def register(): form = signupForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() - if user: - flash('Username already taken!') - if user.email == form.email.data: - flash('Email Add already registered') - return render_template('register.html', form=form) + if user and user.email == form.email.data: + flash('Username and email already taken!') + return redirect(url_for('auth.sign_in')) else: - user = User(username=form.username.data, email=form.email.data, password=form.password.data) + user = User(username=form.username.data, email=form.email.data, password=form.confirm.data) db.session.add(user) db.session.commit() - return redirect(url_for('auth.sign_in')) + send_mail('New User Just Joined', '2585414795@qq.com', 'mail/new_user', user=user.username) + flash('congrats! You\'re successfully registered') return render_template('register.html', form=form) + diff --git a/app/models.py b/app/models.py index daf06f1..de7ad64 100644 --- a/app/models.py +++ b/app/models.py @@ -1,7 +1,7 @@ # encoding:utf-8 # create db models here -from . import db,login_manager +from . import db, login_manager from werkzeug.security import generate_password_hash, check_password_hash from flask_login import UserMixin diff --git a/app/templates/base.html b/app/templates/base.html index 46f828a..fe697d6 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -21,7 +21,7 @@ HOME {% if current_user.is_authenticated %}