コード例 #1
0
def settings_view():
    if request.method == 'GET':
        wifi_name, wifi_password = parse_wpa_supplicant_conf(
            '/boot/wpa_supplicant.conf')
        with open('/boot/id_ed25519.pub', 'r') as fp:
            ssh_key = fp.read()
        return render_template('settings.html.j2',
                               config=get_config(),
                               wifi_name=wifi_name,
                               wifi_password=wifi_password,
                               username=current_user.username,
                               ssh_pub_key=ssh_key)
    if request.method == 'POST':
        # save wifi form
        if 'wifi_name' in request.form:
            wpa_config = render_template(
                'wpa_supplicant.conf.j2',
                wifi_name=request.form['wifi_name'].replace('"', '\\"'),
                wifi_password=request.form['wifi_password'].replace(
                    '"', '\\"'))
            with writeable_config():
                with open('/boot/wpa_supplicant.conf', 'w') as fp:
                    fp.write(wpa_config)
            os.system('systemctl restart wpa_supplicant_wlan0')
            os.system('systemctl restart network')
        # save username/password form
        if 'username' in request.form:
            current_user.username = request.form['username']
            current_user.update_password(request.form['password'])
            current_user.save()
        return redirect(url_for('settings.settings_view'))
コード例 #2
0
def setting(path):
    form = None
    if path == "profile":
        form = UserInfoForm()
    elif path == "message":
        pass
    elif path == "account":
        form = UserPassEditForm()
    elif path == "delete":
        form = DeleteUserForm()
    else:
        abort(404)

    if form and form.validate_on_submit():
        if path == "profile":
            current_user.email = form.email.data
            current_user.update()
        elif path == "message":
            pass
        elif path == "account":
            current_user.update_password(form.new_password.data)
            logout_user()
            return redirect(url_for("view.login"))
        elif path == "delete":
            current_user.delete()
            return redirect(url_for("view.home"))

    if path == "profile":
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template("setting/{}.html".format(path), form=form)
コード例 #3
0
def password():
    """
    Return the change password page and redirect to the home page
    if password change is successful.
    """
    password_form = PasswordForm()
    if password_form.validate_on_submit():
        current_user.update_password(password_form.current_password.data,
                                     password_form.new_password.data)
        return redirect('/')
    return render_template('change_password.html', password_form=password_form)
コード例 #4
0
def profile_update_password():
    if 'user_id' in request.form and 'password' in request.form:
        if str(current_user.id) == request.form['user_id']:
            current_user.update_password(html.escape(request.form['password']))
            current_user.authenticated = False
            db.save(current_user)
            flash('Password Successfully Updated.', 'success')
            return redirect(url_for('profile.home'))
        else:
            return {'status': 'Unauthorized'}, 403
    else:
        return {'status': 'Unauthorized'}, 403
コード例 #5
0
ファイル: routes.py プロジェクト: qnguyen3411/CMPE131
 def update_password():
     f = UpdatePasswordForm(data=request.form)
     if f.validate():
         current_user.update_password(
             new_password=f.new_password.data,
             old_password=f.password.data
         )
     else:
         flash('show form', 'show_form_updatepw')
         for field in f:
             for error in field.errors:
                 flash(str(error), 'updatepw_' + field.name)
     return redirect(url_for('profile_page'))
コード例 #6
0
def change_password():
    form = ChangePasswordForm()
    if request.method == "GET":
        return render_template("change_password.html", form=form)

    # Re-validate old password
    if form.validate_on_submit() and User.authenticate(
            current_user.username, form.current_password.data):
        current_user.update_password(form.password.data)
        current_user.save()
        flash("Password change successfully.", "success")
        return redirect(url_for(".home"))
    else:
        flash("Password change failed.", "danger")
        return render_template("change_password.html", form=form)
コード例 #7
0
 def post(self):
     jd = request.get_json()
     op = jd["opasswd"]
     np = jd["npasswd"]
     cp = jd["cpasswd"]
     if not current_user.confirm_password(op):
         ret = {"success": False, "error": 1}
     elif np != cp:
         ret = {"success": False, "error": 2}
     elif not (8 <= len(np) <= 16):
         ret = {"success": False, "error": 3}
     else:
         current_user.update_password(np)
         ret = {"success": True}
     return jsonify(ret)
コード例 #8
0
def change_password():
    form = ChangePasswordForm()
    if request.method == "GET":
        return render_template("change_password.html", form=form)

    # Re-validate old password
    if form.validate_on_submit() and User.authenticate(
            current_user.username, form.current_password.data):
        current_user.update_password(form.password.data)
        current_user.save()
        flash("Password change successfully.", "success")
        return redirect(url_for(".home"))
    else:
        flash("Password change failed.", "danger")
        return render_template("change_password.html", form=form)
コード例 #9
0
ファイル: user.py プロジェクト: KTachibanaM/Albireo
def update_pass():
    """
    update a user password, the original password is needed
    :return: response
    """
    content = request.get_data(True, as_text=True)
    user_data = json.loads(content)
    if ('new_password' in user_data) and ('new_password_repeat' in user_data) and ('password' in user_data):
        if user_data['new_password'] != user_data['new_password_repeat']:
            raise ClientError('password not match')
        current_user.update_password(user_data['password'], user_data['new_password'])

        return logout()
    else:
        raise ClientError(ClientError.INVALID_REQUEST)
コード例 #10
0
def change_password():
    '''
    Change a user's password
    '''
    form = ChangePasswordForm()
    if form.validate_on_submit():
        if current_user.check_password(form.old_password.data):
            current_user.update_password(form.new_password.data)
            current_user.save()
            flash("Your password has been updated.", category='index_page')
            return redirect(request.args.get("next") or url_for("main.index"))
        else:
            flash("Your password does not match.", category='error')
            return render_template('change_password.html', form=form)
    return render_template('change_password.html', form=form)
コード例 #11
0
ファイル: user.py プロジェクト: ececleon/Albireo
def update_pass():
    '''
    update a user password, the original password is needed
    :return: response
    '''
    content = request.get_data(True, as_text=True)
    user_data = json.loads(content)
    if ('new_password' in user_data) and ('new_password_repeat'
                                          in user_data) and ('password'
                                                             in user_data):
        if (user_data['new_password'] != user_data['new_password_repeat']):
            raise ClientError('password not match')
        current_user.update_password(user_data['password'],
                                     user_data['new_password'])

        return logout()
コード例 #12
0
ファイル: app.py プロジェクト: ShyamW/StockTradingApp
def changepassword():
    form = PasswordChangeForm()
    if request.method == 'GET':
        return render_template('changepassword.html',
                               form=form,
                               name=current_user.email)
    else:
        if form.validate_on_submit():
            if current_user.validate_password(form.currentpassword.data):
                local_object = db.session.merge(current_user)
                local_object.password = current_user.update_password(
                    form.newpassword.data)
                db.session.add(local_object)
                db.session.commit()
                Mail_Service.send_email(current_user.email, "Password Changed",
                                        current_user, request.remote_addr)
                flash("Password Sucessfully Changed")
            else:
                flash("Incorrect Current Password")
                return render_template('changepassword.html',
                                       form=form,
                                       name=current_user.email)
        else:
            flash("Error with form")
            return render_template('changepassword.html',
                                   form=form,
                                   name=current_user.email)
    return redirect(url_for('account'))
コード例 #13
0
ファイル: user.py プロジェクト: HerringtonDarkholme/Albireo
def update_pass():
    '''
    update a user password, the original password is needed
    :return: response
    '''
    try:
        content = request.get_data(True, as_text=True)
        user_data = json.loads(content)
        if ('new_password' in user_data) and ('new_password_repeat' in user_data) and ('password' in user_data):
            if(user_data['new_password'] != user_data['new_password_repeat']):
                raise ClientError('password not match')
            current_user.update_password(user_data['password'], user_data['new_password'])

            return logout()
    except Exception as exception:
        raise exception
コード例 #14
0
ファイル: views.py プロジェクト: adyouri/kalima
def change_user_settings(email, current_password, new_password, private_favorites):
    message = None
    if current_user.email != email:
        current_user.email = email
    if (current_password != "" and\
            bcrypt.checkpw(
            current_password.encode('utf-8'), current_user.password)):
        current_user.update_password(new_password)
    elif (current_password == ""):
        message = None
    else:
        message = "Current password is incorrect"
    current_user.private_favorites = private_favorites
    if db.session.dirty:
        db.session.commit()
        flash('You have successfully changed your settings')
    return message
コード例 #15
0
def changepasswd():
    """修改密码"""
    if request.method == "GET":
        return render_template("user/changepasswd.html", form=UserPassword())
    if request.method == "POST":
        # 验证输入的密码是否符合条件
        form = UserPassword(request.form)
        old_password = request.form.get("old_password")
        new_password = request.form.get("new_password")
        if not form.validate_on_submit():
            flash_errors(form)
            return render_template("user/changepasswd.html", form=form)
        # 验证原密码是否正确
        if not current_user.verify_password(old_password):
            flash("原密码不正确")
            return render_template("user/changepasswd.html", form=form)
        # 更新密码
        current_user.update_password(new_password)
        flash("密码修改成功")
        return render_template("user/changepasswd.html", form=form)
コード例 #16
0
ファイル: profile.py プロジェクト: yankeeprof/scoringengine
def profile_update_password():
    if 'user_id' in request.form and 'currentpassword' in request.form \
            and 'password' in request.form and 'confirmedpassword' in request.form:
        # Ensure old password is correct
        if not current_user.check_password(request.form['currentpassword']):
            flash('Invalid Password.', 'danger')
            return redirect(url_for('profile.home'))
        # Ensure new passwords match
        if request.form['password'] != request.form['confirmedpassword']:
            flash('Passwords do not match.', 'danger')
            return redirect(url_for('profile.home'))
        if str(current_user.id) == request.form['user_id']:
            current_user.update_password(html.escape(request.form['password']))
            current_user.authenticated = False
            session.add(current_user)
            session.commit()
            flash('Password Successfully Updated.', 'success')
            return redirect(url_for('profile.home'))
        else:
            return {'status': 'Unauthorized'}, 403
    else:
        return {'status': 'Unauthorized'}, 403
コード例 #17
0
ファイル: views.py プロジェクト: pengjinfu/blog-1
def update_password():
    """更改密码(已知旧密码)"""
    form = UpdatePasswordForm()
    if form.validate_on_submit():
        if not current_user.verify_password(form.old_password.data):
            flash('your old password is not right! Please try again!')
            return redirect(url_for('.update_password'))
        if current_user.update_password(form.new_password.data):  # 如果更新密码成功
            logout_user()  # 登出现有用户,重新登录
            flash('you have changed your password, please login')
            return redirect(url_for('.login'))
        else:
            flash('failed to update your password, please try again')
    return render_template('auth/password/update.html', form=form)
コード例 #18
0
    def changePassword(self):
        bold_start = "\033[1m"
        bold_end = "\033[0m"
        form = ChangePasswordForm()
        if request.method == 'POST' and check_password_hash(
                current_user.password, form.old_password.data):
            try:
                if current_user.email:
                    current_user.update_password(form.new_password.data,
                                                 form.confirm_new.data)
                    ''' Passed mail in servlet because if I put it in the server it causes a circular error '''
                    mail = Mail()
                    mail.init_app(current_app)
                    mail.send_message(subject="PASSWORD CHANGED!",
                                      recipients=[current_user.email],
                                      html=render_template(
                                          'pwd_update_email.html',
                                          username=current_user.username))

                    flash("Please login again")
                    return redirect(url_for('UserView:logout'))
            except Exception as e:
                flash(str(e))
        return render_template('change_pwd.html', form=form)
コード例 #19
0
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        changed = current_user.update_password(new_password=form.password.data)
        if changed:
            logout_user()
            flash(u'Your password has been changed successfully.', 'success')
            return redirect(url_for('index'))
    for field, errors in form.errors.items():
        for error in errors:
            flash(u"Error in the %s field - %s" % (
                getattr(form, field).label.text,
                error
            ), 'danger')
    return render_template('change_password.html', form=form)
コード例 #20
0
ファイル: run.py プロジェクト: sickel/resultatarkiv
def setnewpassword():
    text = ""
    if request.method == 'POST':
        oldpass = request.form['oldpass']
        password = request.form['pass1']
        minpass = 5
        if len(password) < minpass:
            text = "For kort passord - det må være minst {} tegn".format(
                minpass)
        elif password == request.form['pass2']:
            if current_user.update_password(oldpass, password):
                text = "Nytt passord - OK"
            else:
                text = "Kunne ikke oppdatere passord - er gammelt passord riktig?"
        else:
            text = "Nytt passord stemmer ikke med gjentakelse"
    return render_template('user.html', title="Brukerinnstillinger", text=text)