def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('home')) user = User.verify_reset_token(token) if user is None: flash('That is an invalid or expired token', 'warning') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashed_password db.session.commit() flash('Your password has been updated! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset Password', form=form)
def register_post(): register = RegistrationForm() if register.validate_on_submit(): flash('Account created for {}'.format(register.username.data), 'success') u = User(register.password.data, register.email.data, register.username.data) try: db_session.add(u) db_session.commit() print("data inserted") except: db_session.rollback() return redirect('/login') return render_template('register.htm', title='Register Page', register=register)
def regist_post(): email = request.form.get('email') passwd = request.form.get('passwd') passwd2 = request.form.get('passwd2') nickname = request.form.get('nickname') if passwd != passwd2: flash("암호를 정확히 입력하세요!!") return render_template("regist.html", email=email, nickname=nickname) else: u = User(email, passwd, nickname, True) try: db_session.add(u) db_session.commit() except: db_session.rollback() flash("%s 님, 가입을 환영합니다!" % nickname) return redirect("/login")
def idx(): ret = 'OK' try: # Create(insert) u = User('*****@*****.**', 'hong') db_session.add(u) print("user.id=", u.id) # Read(select)1 # u = User.query.filter(User.id == 1).first() # lst = User.query.all() # Read(select)2 # s = db_session() # result = s.execute('select id, email, nickname from User where id > :id', {'id':1}) # Record = namedtuple("User", result.keys()) # rrr = result.fetchall() # print(">>", type(result), result.keys(), rrr) # records = [Record(*r) for r in rrr] # for r in records: # print(r, r.nickname, type(r)) # s.close() db_session.commit() # ret = User.query.all() except SQLAlchemyError as sqlerr: db_session.rollback() print("SqlError>>", sqlerr) except: print("Error!!") finally: db_session.close() # return "RET=" + str(ret) return render_template('main.html', userlist=ret)
def register_post(): register = RegistrationForm() if register.validate_on_submit(): flash('Account created for {}'.format(register.username.data), 'success') u = User(register.password.data, register.email.data, register.username.data) try: subject = "회원가입 메일" mail = "회원가입을 축하합니다" # s = URLSafeTimedSerializer('The_Key') # QQQ secret key 바꾸기 # token = s.dumps(register.email.data, salt = 'email_confirm') # confirm_email(token) # link = url_for('confirm_email', token = token, _external = True) send_email(subject, mail ,register.email.data) db_session.add(u) db_session.commit() print("data inserted") except Exception as err: db_session.rollback() print("ROLL BACK FOR REGISTER", err) return redirect('/login') return render_template('register.htm', title='Register Page', register = register)