示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
文件: user.py 项目: charlee/flashpins
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)
示例#5
0
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)
示例#6
0
文件: user.py 项目: charlee/flashpins
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)
示例#8
0
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)
示例#9
0
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)
示例#10
0
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)
示例#11
0
 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
示例#12
0
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()
示例#13
0
 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()