Exemplo n.º 1
0
def addInviteKey():
    form = InviteKey()
    if form.validate_on_submit():
        if bcrypt.check_password_hash(current_user.password,
                                      form.password.data):
            inviteKeyList.append(form.key.data)
            flash('Added Invite Key.', 'success')
        else:
            flash('Password does not match.', 'danger')
    # Show page to the user
    return render_template('addInviteKey.html', keys=inviteKeyList, form=form)
Exemplo n.º 2
0
def changePassword():
    form = ChangePassword()
    if form.validate_on_submit():
        if bcrypt.check_password_hash(current_user.password,
                                      form.password.data):
            if form.newPassword.data == form.confirmNewPassword.data:
                current_user.password = bcrypt.generate_password_hash(
                    form.newPassword.data).decode('utf-8')
                db.session.commit()
                flash('Password Updated.', 'success')
                return redirect(url_for('settings'))
            else:
                flash(
                    '"New Password" and "Confirm New Password" fields do not match.',
                    'warning')
        else:
            flash('Password does not match.', 'danger')
    # Show page to the user
    return render_template('changePassword.html', form=form)
Exemplo n.º 3
0
def deleteAccount():
    form = DeleteAccount()
    if form.validate_on_submit():
        if bcrypt.check_password_hash(current_user.password,
                                      form.password.data):
            if current_user.username == 'admin':
                flash('Admin account cannot be deleted.', 'warning')
            else:
                # Delete the user
                #db.session.delete(current_user)
                db.session.execute('Delete from user where uid=:uid',
                                   {'uid': current_user.uid})
                db.session.commit()
                # Tell user
                flash('Account Deleted.', 'success')
                # Log out user
                logout_user()
                return redirect(url_for('login'))
        else:
            flash('Password does not match.', 'danger')
    # Show page to the user
    return render_template('deleteAccount.html', form=form)
Exemplo n.º 4
0
def changeUserName():
    form = ChangeUsername()
    if form.validate_on_submit(
    ) and form.username.data != current_user.username:
        if bcrypt.check_password_hash(current_user.password,
                                      form.password.data):
            if current_user.username == 'admin':
                flash('Admin account change username.', 'warning')
            else:
                # Update username
                if form.username.data != "":
                    current_user.username = form.username.data
                    db.session.commit()
                    # Tell user
                    flash('Username Updated.', 'success')
                    return redirect(url_for('settings'))
                else:
                    flash('Username cannot be empty.', 'warning')
        else:
            flash('Password does not match.', 'danger')
    # Show page to the user
    return render_template('changeUsername.html', form=form)
Exemplo n.º 5
0
def login():
    # Check if logged in
    if current_user.is_authenticated:
        return redirect(url_for('listApp'))
    # login get Login Form
    form = LogInForm()

    if form.validate_on_submit():
        # Get User using username
        user = User.query.filter_by(username=form.username.data).first()

        # Check password
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            # User login
            login_user(user, remember=form.remember.data)
            # Log the user
            logUser(request, current_user)
            return redirect(url_for('listApp'))
        else:
            flash('Login Unsuccessful. Please check username and password',
                  'danger')
    return render_template('login.html', title='Login', form=form)