def register(): if current_user.is_authenticated: redirect(url_for('home')) form = StudentRegistrationForm() if form.validate_on_submit(): StudentObj = Student() StudentObj.username = form.username.data StudentObj.email = form.email.data # generating a hashed password hashed_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') StudentObj.password = hashed_pass StudentObj.phone = form.phone.data StudentObj.birthday = form.birthday.data StudentObj.gender = form.gender.data try: db.session.add(StudentObj) db.session.commit() send_email(StudentObj.email, 'New User Registration', '/mail/new_user', name=StudentObj.username) send_message( 'Hey,' + StudentObj.username + 'Thanks for registering with us..This year on ' + str(StudentObj.birthday) + 'lets rock!', str(StudentObj.phone)) except Exception as e: print(e + StudentObj.id) pass flash('You have successfully registered', 'success') return redirect(url_for('home')) return render_template('register.html', title='Register', form=form, sidebar=True)
def register(): if current_user.is_authenticated: redirect(url_for('main')) title = "Register" meta_description = "DJs, Live Musicians and Booking Agents are welcome to use this tool." \ " You can build nice PDF Riders for free, but you have to Register." form = RegistrationForm() if request.method == "GET": flash( 'You are probably going to rebuild the document multiple times,' ' so I have to store your data somehow. It is not used anywhere and you will have an opportunity' ' to completely delete yourself after you are done.', 'info') 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() login_user(user, remember=True) flash(f'User {user} created', 'success') return redirect(url_for('main')) return render_template('register.html', title=title, form=form, meta_description=meta_description)
def change_password(): title = "Change Password" meta_description = "Change Password Here." form = ChangePasswordForm() if form.validate_on_submit(): if form.validate_on_submit(): user = User.query.get(current_user.id) if user and bcrypt.check_password_hash(user.password, form.password.data): new_hashed_password = bcrypt.generate_password_hash( form.new_password.data).decode('utf-8') User.query.filter_by(id=current_user.id).update( {User.password: new_hashed_password}) db.session.commit() logout_user() flash(f'Password Changed Successfully', 'success') return redirect(url_for('login')) else: flash( f'An Error Occurred. You Might Have Typed a Wrong Password', 'warning') return render_template('change_password.html', title=title, meta_description=meta_description, form=form)
def update_password(user_id, password): """ Update user's password """ user = User.ref(user_id) if user: password_digest = bcrypt.generate_password_hash(password) user.update(password_digest=password_digest)
def register(): 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, password=hashed_password) db.session.add(user) db.session.commit() flash('Account created!') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def new_user(email, password): """ Make a new user, save it and return user_id """ # create new user and save it password_digest = bcrypt.generate_password_hash(password) user_id = User.new(email=email, screen_name='', password_digest=password_digest) return user_id
def register(): form = RegistrationForm() if form.validate_on_submit(): # Connected the registration page to database 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 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(f'Your account has been created, you can now Login!', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def reset_token(token): student = Student.get_verify_token(token) if student is None: flash('Invalid or expired tokens', 'danger') return redirect(url_for('reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashed_pass = bcrypt.generate_password_hash( form.password.data).decode('utf-8') student.password = hashed_pass db.session.commit() flash('Your password has been updated', 'success') return redirect(url_for('login')) return render_template('reset_token.html', title='Reset password', form=form)
def reset_token(token): title = "Password Reset" meta_description = "Reset Password Here." 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=title, meta_description=meta_description, form=form)
def __init__(self, id, agent_name, agent_email, password, agent_license="", agent_phone="", agent_phone_china="", agent_wechat="", agent_office="", agent_qrcode="", last_login=None): self.id = id self.password = bcrypt.generate_password_hash(password) self.registered_on = datetime.datetime.now() self.agent_name = agent_name self.agent_license = agent_license self.agent_phone = agent_phone self.agent_phone_china = agent_phone_china self.agent_wechat = agent_wechat self.agent_email = agent_email self.agent_office = agent_office self.agent_qrcode = agent_qrcode self.last_login = last_login
def create_admin(pw, user, email): hashed_password = bcrypt.generate_password_hash(pw).decode('utf-8') admin = User(username=user, email=email, password=hashed_password) db.session.add(admin) db.session.commit()
def password(self, password): """ Method helps set the password property for the class """ self._password = bcrypt.generate_password_hash( password, app.config.get('BCRYPT_LOG_ROUNDS')).decode()