Example #1
0
def account_view():
    account_form = AccountForm(prefix='account', obj=current_user)
    change_password_form = ChangePasswordForm(prefix='change-password')
    change_email_form = ChangeEmailForm(prefix='change-email')

    if 'account-submit' in request.form:
        if account_form.validate():
            current_user.first_name = account_form.first_name.data
            current_user.last_name = account_form.last_name.data
            db.session.commit()
            flash('Account updated.', 'success')
            return redirect(url_for('auth.account'))
    elif 'change-password-submit' in request.form:
        if change_password_form.validate():
            password = change_password_form.new_password.data
            current_user.set_password(password)
            db.session.commit()
            flash('Password updated.', 'success')
            return redirect(url_for('auth.account'))
    elif 'change-email-submit' in request.form:
        if change_email_form.validate():
            email = change_email_form.new_email.data
            current_user.email = email
            db.session.commit()
            flash('Email updated.', 'success')
            return redirect(url_for('auth.account'))

    context = dict(
        account_form=account_form,
        change_password_form=change_password_form,
        change_email_form=change_email_form,
    )

    return render_template('account.html', **context)
Example #2
0
def mypage():
    form = MypageForm(request.form)
    msg = None
    if request.method == "POST":
        if current_user.check_password(form.cpassword.data):
            msg = ""
            if form.password.data:
                if len(form.password.data) < 4:
                    msg = "password - Field must be at least 4 characters long."
                    return render_template("mypage.html", msg = msg, form = form, entrance_type = config.entrance_type)
                elif form.password.data == form.confirm.data:
                    msg += "password "
                    current_user.set_password(form.password.data)
                else:
                    msg = "Passwords must match"
                    return render_template("mypage.html", msg = msg, form = form, entrance_type = config.entrance_type)
            if form.name.data and form.name.data != current_user.name:
                msg += "name "
            if msg:
                msg += "changed successfully"
            db_session.commit()
        else:
            msg = "wrong current password"

    return render_template("mypage.html", msg = msg, form = form, entrance_type = config.entrance_type)
Example #3
0
 def trocar_senha(self, ):
     # return "Trocar Senha: Falta implementar"
     form = TrocarSenhaForm()
     if form.validate_on_submit():
         current_user.set_password(form.new_password.data)
         db.session.add(current_user)
         db.session.commit()
         return redirect(url_for('index'))
     return render_template("redefinir_senha.html", form=form)
Example #4
0
def change_password():
    form = PasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.password.data)
        current_user.save()
        return redirect(url_for('user.profile'))
    else:
        flash_errors(form)

    return render_extensions('users/change_password.html', resetform=form)
Example #5
0
def change_password():
    if( request.method == "POST"):
        form = ChangePasswordForm( request.form)
        if( form.validate()):
            current_user.set_password( form.password1.data)
            flash( "Your password was changed successfully.", "success")
            return redirect( "/")
    else:
        form = ChangePasswordForm()
    return render_template( "auth/change_password.html", **locals())
Example #6
0
def settings():
    form = SettingsForm(request.form)
    if form.validate_on_submit():
        if form.newpassword.data and form.oldpassword.data and form.repeat.data:
            current_user.set_password(form.newpassword.data)
            current_user.save()
            flash("Successfully set new password")
        return redirect(url_for('settings'))
    else:
        return render_template("settings.html", form=form)
Example #7
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.set_password(form.password.data)
            current_user.save()
            flash('Your password has been updated')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.')
    return render_template("auth/change_password.html", form=form)
Example #8
0
def changepassword():
    form = ChangePasswordForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            oldpassword = form['oldpassword'].data
            password = form['password'].data
            if not current_user.check_password(oldpassword):
                flash('Current password incorrect', 'error')
            else:
                current_user.set_password(password)
                current_user.save()
                flash('Password successfully changed')
                return redirect(url_for('index'))
    return render_template('changepassword.html', form=form)
Example #9
0
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        password = form.new_password.data
        current_user.set_password(password)
        db.session.commit()
        flash('Password updated.', 'success')
        return redirect(url_for('radar.index'))

    context = dict(
        form=form,
    )

    return render_template('change_password.html', **context)
Example #10
0
def user_details():
    """Edits personal user informations"""

    form = forms.UserDetailsForm(username=current_user.username,
                                 display_name=current_user.display_name)

    if form.validate_on_submit():
        current_user.display_name = form.display_name.data
        if form.password.data:
            current_user.set_password(form.password.data)

        db.Session.commit()
        flash(_(u"Profile successfully updated"), 'success')
        return redirect(url_for('user_details'))

    return render_template('user_details.html', form=form)
def user_profile_password():

    # Validate password for form
    def _check_password(pwd):
        return user_api_client.verify_password(current_user.id, pwd)
    form = ChangePasswordForm(_check_password)

    if form.validate_on_submit():
        current_user.set_password(form.new_password.data)
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template(
        'views/user-profile/change-password.html',
        form=form
    )
Example #12
0
File: api.py Project: caocf/youjiao
def reset_password():
    # validate
    schema = ResetPasswordSchema()
    # import ipdb; ipdb.set_trace()
    # TODO: supprot json and form input, or just support json
    # if request.content_type == 'application/json':
    #    get data from request.json
    # if request.content_type == 'form...'
    #   get data from form

    data, error = schema.load(request.get_json())
    # data, error = schema.load({'password': '******'})
    if error:
        return jsonify(error), 400
    current_user.set_password(data['password'])
    # get data
    return jsonify(data)
Example #13
0
def settings():
    form = SettingsForm(request.form)
    if form.validate_on_submit():
        if form.newpassword.data and form.oldpassword.data and form.repeat.data:
            # Handling the decryption and re-encryption of the passwords in case of a password change
            new_pwdh = PasswordManager.generate_pwdh_from_password(form.newpassword.data)
            for device in Device.query.all():
                # Decrypts the password using the session pwdh and encrypts it with the new pwdh (not in session)
                device.password = PasswordManager.encrypt_string(device.decrypt_password(), new_pwdh)
                device.save(encrypt=False)  # The password is already encrypted
            PasswordManager.set_session_pwdh(form.newpassword.data)
            current_user.set_password(form.newpassword.data)
            current_user.save()
            flash("Successfully set new password", "info")
        return redirect(url_for('settings'))
    else:
        return render_template("settings.html", form=form, active_page="settings")
Example #14
0
 def password(form):
     password = form.password.data
     password_n = form.password_n.data
     if current_user.check_password(password):
         current_user.password = current_user.set_password(password_n)
         db.session.commit()
         logout_user()
         return True
     return False
Example #15
0
def edit_profile(username):
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.data
        if form.new_password.data:
            current_user.set_password(form.new_password.data)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user', username=form.username.data))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Example #16
0
def change_user_password(username):
    if current_user.is_authenticated and (str(current_user.username) == username or current_user.is_admin):
        form = UserChangePasswordForm()
        if form.validate_on_submit():
            current_user.set_password(form.password.data)
            db.session.commit()
            homeberry_flash(FLASH_SUCCESS, "Changed user's password.")

            if current_user.is_admin:
                return redirect('/admin')
            else:
                return redirect('/')
        elif request.method == 'POST':
            homeberry_flash(FLASH_ERROR, "Unable to change password.")

        return render_template('change_password.html', form=form)
    else:
        abort(403)
Example #17
0
def password():
    form = PasswordOnlyForm()

    if form.validate_on_submit():
        if check_password_hash(current_user.password_hash, form.password.data):
            flash("You must choose a different password.", "danger")
        else:
            current_user.set_password(form.password.data)
            current_user.must_change_password = False
            flash("Password was changed.", "success")

        db.session.commit()

        return redirect(url_for('index'))

    return render_template("user/password.html",
                           form=form,
                           title=page_title("Change Password"))
Example #18
0
def change_password(username: str) -> Union[Dict[str, Any], Tuple[Union[str, Any], int]]:
    if current_user.username != username:
        return {'error': True, 'reason': 'You are not authorized to change this user\'s password.'}, 403

    old_password = request.form.get('old-password', '')
    new_password = request.form.get('new-password', '')
    new_password_confirm = request.form.get('new-password-confirm', '')

    if not current_user.check_password(old_password):
        return {'error': True, 'reason': 'The old password you entered doesn\'t match your current account password.'}

    pw_valid, pw_message = check_password_criteria(new_password, new_password_confirm)
    if pw_valid:
        current_user.set_password(new_password)
        send_password_changed(current_user)
        return {'error': False, 'reason': pw_message}

    return {'error': True, 'reason': pw_message}
Example #19
0
def change_pw():
    form = ChangePWForm()
    if current_user.is_authenticated:
        if form.validate_on_submit():
            if current_user.check_password(form.old_password.data):
                current_user.set_password(form.new_password.data)
                db.session.commit()
                flash('Password successfully changed')
                return redirect(url_for('change_pw'))
            else:
                flash('Old password is incorrect')
                return redirect(url_for('change_pw'))
    else:
        return redirect(url_for('login'))
    return render_template('change_pw.html',
                           header='Change Password',
                           navbar_access=navbar_access(),
                           form=form)
Example #20
0
def edit():
    form = ChangeForm()
    if not current_user.is_authenticated:
        flash('你还没登陆呢')
        redirect('/')
    if request.method == 'POST':
        oldpassword = request.form['oldpassword']
        newpassword = request.form['newpassword']
        confirm = request.form['confirm']
        if not current_user.check_password(oldpassword):
            flash('旧密码不正确')
            return redirect('/change')
        if not confirm == newpassword:
            flash('两次输入密码不一致')
            return redirect('/change')
        current_user.set_password(newpassword)
        db.session.commit()
        flash('修改成功')
    return render_template('change.html', form=form)
Example #21
0
def change_pass():
    reset_form = ResetPasswordForm()
    reg_form = RegistrationForm()
    users = User.query.all()

    if reset_form.validate_on_submit():
        print("ola")
        current_user.set_password(reset_form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('auth.settings'))

    # handle the login form
    # render the same template to pass the error message
    # or pass `form.errors` with `flash()` or `session` then redirect to /
    return render_template('auth/Settings.html',
                           reset_form=reset_form,
                           reg_form=reg_form,
                           users=users)
Example #22
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.email = form.email.data
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        password = request.form.get('password', None)
        if password is None:
            db.session.commit()
        else:
            current_user.set_password(form.password.data)
            db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
        form.email.data = current_user.email
    return render_template('edit_profile.html', title='Edit Profile', form=form)
Example #23
0
def change_password():
    if current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form = forms.ChangePasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=current_user.username).first()
        if not user.check_password(form.old_password.data):
            flash('Incorrect password, please try again.')
            return redirect(url_for('auth.change_password'))
        if user.check_password(form.new_password.data):
            flash('You already have this password, please try again.')
            return redirect(url_for('auth.change_password'))
        current_user.set_password(form.new_password.data)
        db.session.commit()
        flash('Password successfully updated.')
        return redirect(url_for('main.user', username=current_user.username))
    return render_template('auth/change_password.html',
                           title='Change Password',
                           form=form)
Example #24
0
def change_pass():
    """
    Change user password.
    """
    if request.method == "POST":
        curr_pass = request.form.get('curr_pass')
        new_pass = request.form.get('password')
        if current_user.check_password(curr_pass):
            # New pass should be different than current one.
            if current_user.check_password(new_pass):
                flash(
                    'The new password should be different from the current one!',
                    'danger')
                return redirect(url_for('auth_bp.change_pass'))
            current_user.set_password(new_pass)
            if current_user.pass_change_req:
                current_user.pass_change_req = False
            db.session.commit()
            current_app.logger_auth.info(
                f'User "{current_user.username}" changed the password')
            flash('Password has been successfully changed!', 'success')
            return redirect(url_for('main_bp.index'))
        else:
            current_app.logger_auth.warning(
                f'Failed password change by "{current_user.username}"')
            current_user.failed_login_attempts += 1
            if current_user.failed_login_attempts >= 3:
                current_user.access_granted = False
                current_app.logger_auth.warning(
                    f'User "{current_user.username}" account has been blocked')
                logout_user()
                flash(
                    'Password change has been unsuccessful. Your account has been blocked!',
                    'danger')
                return redirect(url_for('main_bp.index'))
            db.session.commit()
            current_app.logger_auth.warning(
                f'Failed password change. Current password does not much for '
                f'"{current_user.username}"')
            flash(
                'The current password does not match! Please check your password',
                'danger')
    return render_template('pass_change.html', title='Change Password')
Example #25
0
def edit_profile():
    form = EditProfileForm(current_user.username, current_user.email)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.data
        valid_pass = form.password.data
        if valid_pass:
            current_user.set_password(valid_pass)
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('main.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title=_('Edit Profile'),
                           form=form)
Example #26
0
def modify_password():
    if not current_user.is_active:
        headers = request.headers
        se = Session.query.filter_by(sid=int(headers['session_id']),
                                     uid=int(headers['user_id'])).first()
        if se == None:
            print('session is not connected')
            return json.dumps({'errmsg': '没有建立会话或者会话信息出错'})
        user = User.query.filter_by(id=se.uid).first()
        login_user(user)

    if request.method == 'POST':
        json_data = json.loads(request.data)
        if 'password' not in json_data:
            return json.dump({'errmsg': '没有传递password'})
        current_user.set_password(json_data['password'])
        db.session.commit()
        return json.dumps('修改密码成功')
    return json.dumps({'errmsg': '没有使用POST请求'})
Example #27
0
def change_password():
    form = ChangePasswordForm()
    if request.method == 'POST':
        if form.validate_on_submit:
            if current_user.check_password(
                    form.current_password.data
            ) and form.password.data == form.password2.data:
                current_user.set_password(form.password.data)
                db.session.commit()
                flash(_('Your password has been updated!'))
                return redirect(url_for('user',
                                        username=current_user.username))
            else:
                flash(_('Please make sure to fill out all fields correctly'))
                return redirect(url_for('change_password'))
    return render_template('change_password.html',
                           user=current_user,
                           form=form,
                           title=_('Change Password'))
Example #28
0
def change_passwd():
    '''修改密码'''

    cc = current_user.username
    q = base.DB(settings.PG_DB)
    cc_name = q.get_cc_name(cc)

    q.close()

    if request.method == 'GET':
        return render_template('tool/password.html', cc_name=cc_name)

    if request.method == 'POST':
        pwdold = request.form['pwdold']
        pwdnew = request.form['pwdnew']
        pwdconfirm = request.form['pwdconfirm']

        if pwdnew.strip() == '':
            msg = '密码不能为空'
            return render_template('tool/password.html',
                                   cc_name=cc_name,
                                   succ=msg)

        ##核对原密码是否正确
        if current_user.check_password(pwdold):
            ##核对新密码的两次输入是否一致
            if pwdnew == pwdconfirm:
                current_user.set_password(pwdnew)
                db.session.commit()
                msg = '修改成功'
                return render_template('tool/password.html',
                                       cc_name=cc_name,
                                       succ=msg)
            else:
                msg = '两次密码输入不一致'
                return render_template('tool/password.html',
                                       cc_name=cc_name,
                                       msg=msg)
        else:
            msg = '原密码输入不正确'
            return render_template('tool/password.html',
                                   cc_name=cc_name,
                                   msg=msg)
Example #29
0
def edit():
    form = EditForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.oldpassword.data):
            flash('Your old password isn\'t correct')
        else:
            current_user.set_password(form.password.data)

        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.bio = form.bio.data
        current_user.spol = form.spol.data
        if form.picture.data is not None:
            filename = secure_filename(form.picture.data.filename)
            form.picture.data.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            current_user.user_picture = filename
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('edit.html', title='Edit Profile', form = form)
Example #30
0
def change_password():
	form = ChangePasswordForm()

	user = Doctor.query.filter_by(user_id=current_user.id).first()

	if form.validate_on_submit():
		if current_user.check_password(form.current_pwd.data):
			if form.current_pwd.data != form.new_password.data:
				current_user.set_password(form.new_password.data)

				db.session.commit()

				return redirect(url_for('doctor.index'))
			else:
				flash('You must use a new password!')
		else:
			flash('Incorrect password!')

	return render_template('doctor/change_password.html', form=form, name=user.name)
Example #31
0
def settings():
    form = SettingForm(obj=current_user)
    change_pwd_form = ChangePasswordForm(prefix='pwd')

    if form.has_been_submitted(request):
        if form.validate_on_submit():
            current_user.blog_title = form.blog_title.data
            current_user.blog_description = form.blog_description.data
            current_user.blog_image = form.blog_image.data
            current_user.blog_image_rounded = form.blog_image_rounded.data
            current_user.blog_bg = form.blog_bg.data
            current_user.blog_bg_public = form.blog_bg_public.data
            current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
            current_user.blog_bg_override = form.blog_bg_override.data
            current_user.blog_bg_repeat = form.blog_bg_repeat.data
            current_user.blog_paginate = form.blog_paginate.data
            current_user.blog_paginate_by = form.blog_paginate_by.data
            current_user.blog_public = form.blog_public.data
            current_user.blog_truncate_posts = form.blog_truncate_posts.data
            current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
            current_user.linkedin_url = form.linkedin_url.data
            current_user.gplus_url = form.gplus_url.data
            current_user.github_url = form.github_url.data
            current_user.twitter_url = form.twitter_url.data
            saved = current_user.save()
            if saved:
                flash("Saved your settings.")
                return redirect(
                    url_for("blog.index", user_slug=current_user.blog_slug))
            else:
                flash("Something went wrong...")

    elif change_pwd_form.has_been_submitted(request):
        if change_pwd_form.validate_on_submit():
            current_user.set_password(change_pwd_form.new_password.data)
            saved = current_user.save()
            if saved:
                flash("Changed your password.")
            else:
                flash("Something went wrong...")
    return render_template("settings.html",
                           form=form,
                           change_pwd_form=change_pwd_form)
Example #32
0
def changepassword():
    password = request.form.get('password', None)
    password2 = request.form.get('password2', None)

    from werkzeug.security import safe_str_cmp
    error = None
    if not password:
        error = 'Last name is required.'

    if not password2 or not safe_str_cmp(password, password2):
        error = "Passwords do not match"

    if error is None:
        current_user.set_password(password)
        flash('Password changed successfully', category='success')
    else:
        flash(error, category='error')

    return redirect(url_for('.edit_profile'))
Example #33
0
def profile():
  form = ProfileForm()
  form.email.data = current_user.email
  context = {
    'form': form
  }
  if form.validate_on_submit():
    db_email = User.query.filter_by(email=form.email.data)
    if current_user.email == form.email.data:
      flash('You already own that email. No change needed')
    if db_email is not None and not db_email != current_user.email:
      flash("That email is already taken. Try again.")
      return redirect(url_for('profile'))
    current_user.email = form.email.data
    current_user.set_password(form.password.data)
    flash("Profile has been updated")
    db.session.commit()
    return redirect(url_for('profile'))
  return render_template('profile.html', **context)
Example #34
0
def changepassword():
    form = ChangepasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(password=form.oldpassword.data):
            current_user.set_password(form.password.data)

            try:
                db.session.commit()
                flash('password changed!', 'info')
            except Exception as e:
                print(e)
                return "There was a problem updating your password"
            return redirect(url_for('profile_bp.user_profile'))
        else:
            flash('Your existing password does not match')
    return render_template('password.html',
                           title='change password',
                           user=current_user,
                           form=form)
Example #35
0
def modify_user():
    data = request.get_json() or {}
    new_username = data.get('new_username')
    new_email = data.get('new_email')
    new_password = data.get('new_password')
    if new_username and new_username != current_user.username:
        current_user.username = new_username
    if new_email and new_email != current_user.email:
        conflicts = User.query.filter_by(email=new_email).all()
        if len(conflicts):
            return bad_request('There is already an account registered withat email address.')
        current_user.email = new_email
    if new_password:
        current_user.set_password(new_password)
    db.session.commit()
    response = jsonify(current_user.to_dict())
    response.status_code = 201
    response.headers['Location'] = url_for('api.get_user')
    return response
Example #36
0
def change_password():
    """Change the current user's password"""
    data = request.form

    if ('password1' not in data.keys()) or \
       ('password2' not in data.keys()) or \
       ('old_password' not in data.keys()):
        return jsonify({
            'status':
            'error',
            'detail':
            'Missing data (password1, password2 or old_password)'
        }), 400

    if not is_password(data['password1']):
        return jsonify({
            'status':
            'error',
            'detail':
            'Password must be at least 8 characters and contain a uppercase letter, a lowercase letter and a number'
        }), 400

    if data['password1'] != data['password2']:
        return jsonify({
            'status': 'error',
            'detail': 'Passwords don\'t match'
        }), 400

    if not current_user.check_password(data['old_password']):
        return jsonify({
            'status': 'error',
            'detail': 'Old password is incorrect'
        }), 400

    current_user.set_password(data['password1'])
    current_user.first_login = False

    db.session.commit()
    return jsonify({
        'status': 'OK',
        'detail': 'Password changed successfuly'
    }), 200
Example #37
0
def update():
    password = request.form.get('password')
    name = request.form.get('name').strip()
    if len(name) > 20:
        return jsonify(errors.Params_error)
    if not password:
        current_user.name = name
    elif password.strip() == "":
        return jsonify(errors.Params_error)
    else:
        current_user.set_password(password)
        current_user.name = name
    current_user.save()
    return jsonify(
        errors.success({
            'msg': '修改成功',
            'uuid': str(current_user.id),
            'name': str(current_user.name),
            'password': '******'
        }))
Example #38
0
def change_password():
    form = ChangePasswordForm()

    if form.validate_on_submit():
        if current_user.is_password_correct(form.current_password.data):
            current_user.set_password(form.new_password.data)
            user_id = current_user.id

            database.session.add(current_user)
            database.session.commit()
            flash('Your password has been updated!', 'success')
            current_app.logger.info(
                f'Password updated for user: {current_user.email}')
            return redirect(url_for('users.show_user_profile',
                                    user_id=user_id))
        else:
            flash('ERROR! Incorrect user credentials!', 'danger')
            current_app.logger.info(
                f'Incorrect password change for user: {current_user.email}')
    return render_template('users/change_password.html', form=form)
Example #39
0
def update_password():
    title = "Lang & Code - Update Account"
    if request.method == "GET":
        return render_template("user/update_password.html", title=title)
    if request.method == "POST":
        current_password = request.form.get("currentPassword")
        new_password = request.form.get("newPassword")
        confirm_new_password = request.form.get("newPasswordConfirmation")
        validate = update_password_validator(current_password, new_password, confirm_new_password)
        if not validate[0]:
            flash('Your password is invalid or do not match. Please try again.', 'is-danger')
            for e in validate[1]:
                flash(e)
            return redirect(url_for("main.index"))
        current_user.set_password(new_password)
        db.session.commit()
        flash('Your password has been updated.', 'is-info')
        return redirect(url_for('main.index'))
    flash('To protect your account, you must re-authenticate to update your password.', 'is-info')
    return render_template('index.html')
Example #40
0
def security():
    form = PasswordForm()
    if form.validate_on_submit():
        if not current_user.check_password(form.password.data):
            flash('The original password is wrong')
            # log information
            current_app.logger.info('"%s" changed password failed',
                                    current_user.username)
            return redirect(url_for('.security'))
        else:
            current_user.set_password(form.passwordnew.data)
            db.session.commit()
            flash('Success! Please login again')
            # log information
            current_app.logger.info('%s changed password',
                                    current_user.username)
            return redirect(url_for('.logout'))
    return render_template('user/pawedit.html',
                           title='password_edit',
                           form=form)
Example #41
0
def account_details():
    """ Account details settings page
    """
    detail_form = AccountDetailForm()
    password_form = UpdatePasswordForm()
    if request.method == 'POST':
        if detail_form.validate_on_submit():
            current_user.update(first_name=detail_form.first_name.data,
                                last_name=detail_form.last_name.data,
                                email=detail_form.email.data)
            flash('Account details updated')
        elif password_form.validate_on_submit():
            current_user.set_password(password_form.new_password.data)
        else:
            flash_form_errors(detail_form)
            flash_form_errors(password_form)
        return redirect(url_for('settings.account_details'))
    return render_template('settings/account-settings.html',
                           detail_form=detail_form,
                           password_form=password_form)
Example #42
0
def change_password():
    error = None
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            if len(form.password.data) < 8:
                error = 'Make sure your password is at least 8 letters'
            elif re.search('[0-9]', form.password.data) is None:
                error = 'Make sure your password has a number in it'
            elif re.search('[A-Z]', form.password.data) is None:
                error = 'Make sure your password has a capital letter in it'
            else:
                current_user.set_password(form.password.data)
                db.session.commit()
                flash('Your password has been updated.')
                return redirect(url_for('profile'))
        else:
            error = 'Old password does not match'
            flash('Invalid password.', 'error')
    return render_template("change_password.html", form=form, error=error)
Example #43
0
def profile():
    if request.method == 'GET':
        form = ProfileForm(data=current_user.data)
        if not current_user.data.get('timezone') and \
                current_user.data.get('digest_allowed'):
            flash(
                '''
    Your timezone has not been stored in the system. To store your
    timezone, make sure it has been correctly determined below and press
    "Submit" below. This is necessary for setting correct times in
    the digest. Otherwise the digest will show all times in UTC.''', 'warning')
    else:
        form = ProfileForm()
        if form.validate_on_submit():
            data = form.data
            email_changed = (form.email.data != current_user.data['email'])
            if email_changed and find_user_by_email(form.email.data):
                flash('Email %s already exists, please pick another email address' % (form.email.data,), \
                        'error')
            else:
                if data['password']:
                    current_user.set_password(form.password.data)
                for key in MyUser.general_fields:
                    current_user.data[key] = data[key]
                if email_changed:
                    current_user.data['state'] = 'disabled'
                    current_user.send_activation_email()
                save_user(current_user)
                if email_changed:
                    flash(
                        'You changed your email address. Your account needs to be re-activated. \
                    An activation email with instructions \
                    has been send to the address %s. Please follow the instructions to activate \
                    your account. If you didn\'t receive the activation email, please check your \
                    spam folder.' % (form.email.data, ), 'warning')
                else:
                    flash('Your changes have been saved.', 'success')
                return redirect(url_for('profile'))
    form.username.data = current_user.get_id()
    flash_errors(form)
    return render_template('profile.html', form=form)
Example #44
0
def changepw():
    """Handler for changing user password."""
    form = PWChangeForm()
    if form.validate_on_submit():
        if not current_user.validate_password(form.oldpw.data):
            flash('Invalid old password')
        elif current_user.set_password(get_db(), form.newpw.data):
            flash('Password successfully changed.')
            return redirect(url_for('mainpage'))
        else:
            flash('Error changing password.')
    return render_template('pwchange.html', form=form)
Example #45
0
def changepw():
    """Handler for changing user password."""
    form = PWChangeForm()
    if form.validate_on_submit():
        if not current_user.validate_password(form.oldpw.data):
            flash('Invalid old password')
        elif current_user.set_password(get_db(), form.newpw.data):
            flash('Password successfully changed.')
            return redirect(url_for('mainpage'))
        else:
            flash('Error changing password.')
    return render_template('pwchange.html', form=form)
Example #46
0
def settings():
    form = SettingForm(obj=current_user)
    change_pwd_form = ChangePasswordForm(prefix='pwd')

    if form.has_been_submitted(request):
        if form.validate_on_submit():
            current_user.blog_title = form.blog_title.data
            current_user.blog_description = form.blog_description.data
            current_user.blog_image = form.blog_image.data
            current_user.blog_image_rounded = form.blog_image_rounded.data
            current_user.blog_bg = form.blog_bg.data
            current_user.blog_bg_public = form.blog_bg_public.data
            current_user.blog_bg_everywhere = form.blog_bg_everywhere.data
            current_user.blog_bg_override = form.blog_bg_override.data
            current_user.blog_bg_repeat = form.blog_bg_repeat.data
            current_user.blog_paginate = form.blog_paginate.data
            current_user.blog_paginate_by = form.blog_paginate_by.data
            current_user.blog_public = form.blog_public.data
            current_user.blog_truncate_posts = form.blog_truncate_posts.data
            current_user.blog_syntax_highlighter_css = form.blog_syntax_highlighter_css.data
            current_user.linkedin_url = form.linkedin_url.data
            current_user.gplus_url = form.gplus_url.data
            current_user.github_url = form.github_url.data
            current_user.twitter_url = form.twitter_url.data
            saved = current_user.save()
            if saved:
                flash("Saved your settings.")
                return redirect(url_for("blog.index", user_slug=current_user.blog_slug))
            else:
                flash("Something went wrong...")

    elif change_pwd_form.has_been_submitted(request):
        if change_pwd_form.validate_on_submit():
            current_user.set_password(change_pwd_form.new_password.data)
            saved = current_user.save()
            if saved:
                flash("Changed your password.")
            else:
                flash("Something went wrong...")
    return render_template("settings.html", form=form, change_pwd_form=change_pwd_form)
Example #47
0
def user_settings():
    if current_user.source == "manual":
        form = SettingsFormPassword(obj=current_user)
    elif current_user.source == "ldap":
        form = SettingsFormLdap(obj=current_user)
    else:
        abort(404)

    if form.validate_on_submit():
        current_user.preferred_language = form.preferred_language.data
        current_user.autowatch = form.autowatch.data
        current_user.allow_invitation_mails = form.allow_invitation_mails.data

        if current_user.source == "manual":
            form.populate_obj(current_user)
            if form.password1.data:
                current_user.set_password(form.password1.data)

        db.session.commit()
        flash(gettext("Your user settings were updated."), "success")
        return redirect(url_for('user_settings'))

    return render_template("user/settings.jade", form=form)
Example #48
0
def password():
    form = PasswordForm()
    if form.validate_on_submit() and request.method == "POST":
        password = form.password.data
        password_n = form.password_n.data
        if current_user.check_password(password):
            current_user.password = current_user.set_password(password_n)
            db.session.commit()
            logout_user()
            return redirect(url_for('auth.login'))
        else:
            flash('password is error')
            return redirect(url_for('setting.password'))
    else:
        if form.errors:
            flash_errors(form)
            return redirect(url_for('setting.password'))
        else:
            return render_template('setting/password.html', form=form)
Example #49
0
 def post(self):
     form = ModifyPasswordForm(formdata=request.form)
     if form.validate_on_submit():
         current_user.set_password(form.data['password'])
         return render_template('user/modify_password.html', modify_success=True, form=form)
     return render_template('user/modify_password.html', form=form)