Example #1
0
def changepass(request):

    saved = None
    if request.method == "POST":

        form = ChangePassForm(request.POST)

        if form.is_valid() and form.is_bound == True:
            old_password = form.cleaned_data["old_password"]
            password1 = form.cleaned_data["password1"]
            if request.user.check_password(old_password):
                request.user.set_password(password1)
                request.user.save()
                return render_to_response(
                    "players/changepass.html",
                    {"form": form, "saved": True, "changePass": True},
                    context_instance=RequestContext(request),
                )
            else:
                return render_to_response(
                    "players/changepass.html",
                    {"form": form, "fail": True, "changePass": True, "badpassword": "******"},
                    context_instance=RequestContext(request),
                )
        return render_to_response(
            "players/changepass.html",
            {"form": form, "fail": True, "changePass": True},
            context_instance=RequestContext(request),
        )

    else:
        form = ChangePassForm({})
        return render_to_response(
            "players/changepass.html", {"form": form, "changePass": True}, context_instance=RequestContext(request)
        )
Example #2
0
def changepswd():
    """
    Handles the change of password for the current user
    """

    form = ChangePassForm()

    if form.validate_on_submit():
        try:
            user = current_user
            print "here"
            if user.verify_password(form.oldpass.data):
                print "pass ok"
                user.password = form.newpass.data
                print user.username.value
                print form.newpass.data
                user.save()
                flash('Parola schimbata!',category='alert-success')
                return redirect(request.args.get('next') or '/home/')
            else:
                raise Exception('Not authorised',form.email.data)

        except Exception as err:
            print err
            flash('Modificarea nu poate fi facuta!', category='alert-danger')

    return render_template('users/edit.html', pagetitle='Schimba parola', form=form)
Example #3
0
def profilepage():
    changepass_form = ChangePassForm()
    # Get old password, compare with form and change password
    if changepass_form.validate_on_submit():
        old_pass = changepass_form.oldpassword.data
        new_pass = changepass_form.newpassword.data
        changepass_form.oldpassword.data = changepass_form.newpassword.data = ""
        if old_pass == current_user.password:
            current_user.password = new_pass
            db.session.commit()
            message = 'Password successfuly changed.'
            return render_template("profilepage.html",
                                   user=current_user,
                                   changepass_form=changepass_form,
                                   message=message)
        # Error message if old password mismatches
        error = 'Old password mismatch.'
        return render_template("profilepage.html",
                               user=current_user,
                               changepass_form=changepass_form,
                               error=error)

    return render_template("profilepage.html",
                           user=current_user,
                           changepass_form=changepass_form)
Example #4
0
def userpref_page():
  ''' Dashbaord User Preferences: This will allow a user to change user preferences, i.e. Password '''
  verify = verifyLogin(app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
  if verify:
    user = User()
    user.get('uid', verify, g.rdb_conn)
    data = startData(user)
    data['active'] = 'dashboard'
    if user.status != "active":
      data['url'] = '/dashboard/mod-subscription'
      tmpl = 'mod-subscription.html'
    else:
      
      ## Start processing the change password form
      form = ChangePassForm(request.form)
      if request.method == 'POST':
        if form.validate():
          result = user.setPass(form.password.data, g.rdb_conn)
          if result:
            data['msg'] = "Password successfully changed"
            print("/dashboard/user-preferences - Password changed")
            data['error'] = False
          else:
            data['msg'] = "Password change was unsuccessful"
            print("/dashboard/user-preferences - Password change failed")
            data['error'] = True
      data['url'] = '/dashboard/user-preferences'
      tmpl = 'user-preferences.html'
    page = render_template(tmpl, data=data, form=form)
    return page
  else:
    return redirect(url_for('login_page'))
 def change_pass(self, user_id):
     form = ChangePassForm(csrf_enabled=False)
     if form.validate_on_submit():
         user = User.query.get(user_id)
         user.password = generate_password_hash(form.passw.data)
         db.session.add(user)
         try:
             db.session.commit()
             flash(u"The password has been changed successfully")
         except Exception:
             flash("Unexpected error")
     return self.render("admin_local/model/change_pass.html", form=form)
Example #6
0
def change_pass():
    form = ChangePassForm()
    error = False
    if request.method == 'POST' and form.validate():
        m = hashlib.md5()
        m.update(form.old_password.data)
        user = database.get_user(username=current_user.username, password=m.hexdigest())
        if user is not None:
            m = hashlib.md5()
            m.update(form.password.data)
            user = database.update_user(username=current_user.username, password=m.hexdigest())
            return redirect(url_for("change_pass_success"))
        error = True
    return render_template("accounts/password_change_form.html", form=form, error=error)
Example #7
0
def changepass():
	form = ChangePassForm()
	user = g.user
	if form.validate_on_submit():
		oldhash = hashlib.sha224(form.oldPass.data + user.email).hexdigest()
		if oldhash == user.passhash:
			newhash = hashlib.sha224(form.newPass.data + user.email).hexdigest()
			user.passhash = newhash
			db.session.add(user)
			db.session.commit()
			flash('Your changes have been saved.')
			return redirect(url_for('user', name = g.user.name))
		else:
			flash('Current password was incorrect.')
			return redirect(url_for('changepass'))
	else:
		return render_template('changepass.html', user = g.user, form = form)
Example #8
0
def userpref_page():
    '''
    Dashbaord User Preferences:
    This will allow a user to change user preferences, i.e. Password
    '''
    verify = verifyLogin(app.config['SECRET_KEY'],
                         app.config['COOKIE_TIMEOUT'], request.cookies)
    if verify:
        user = User()
        user.config = app.config
        user.get('uid', verify, g.rdb_conn)
        data = startData(user)
        data['active'] = 'dashboard'
        if user.status != "active":
            data['url'] = '/dashboard/mod-subscription'
            tmpl = 'member/mod-subscription.html'
        else:
            # Start processing the change password form
            form = ChangePassForm(request.form)
            if request.method == 'POST':
                if form.validate():
                    result = user.checkPass(form.old_password.data, g.rdb_conn)
                    if result:
                        update = user.setPass(form.password.data, g.rdb_conn)
                        if update:
                            print(
                                "/dashboard/user-preferences - Password changed"
                            )
                            flash('Password successfully changed.', 'success')
                        else:
                            print("/dashboard/user-preferences - \
                                  Password change failed")
                            flash('Password change was unsuccessful.',
                                  'danger')
                    else:
                        print(
                            "/login - User change password error: wrong old password"
                        )
                        flash('Old password does not seem valid.', 'danger')
            data['url'] = '/dashboard/user-preferences'
            tmpl = 'member/user-preferences.html'
        page = render_template(tmpl, data=data, form=form)
        return page
    else:
        flash('Please Login.', 'warning')
        return redirect(url_for('user.login_page'))
Example #9
0
def profilepage():
    changepass_form = ChangePassForm()
    # Get old password, compare with form and change password
    if changepass_form.validate_on_submit():
        old_pass = changepass_form.oldpassword.data
        new_pass = changepass_form.newpassword.data
        changepass_form.oldpassword.data = changepass_form.newpassword.data = ""
        if old_pass == current_user.password:
            current_user.password = new_pass
            db.session.commit()
            message = 'Password successfuly changed.'
            return render_template("profilepage.html", user = current_user, changepass_form = changepass_form, message = message)
        # Error message if old password mismatches    
        error = 'Old password mismatch.'
        return render_template("profilepage.html", user = current_user, changepass_form = changepass_form, error = error)

    return render_template("profilepage.html", user = current_user, changepass_form = changepass_form)
Example #10
0
def change_password():
    if 'email' not in session:
        return redirect(url_for('signin'))
    form = ChangePassForm()
    if request.method == 'POST':
        if not form.validate():
            return render_template('change_password.html', form=form)
        else:
            user = User.query.filter_by(email=session['email']).first()
            if user is None:
                return redirect(url_for('signin'))
            else:
                user.pwdhash = generate_password_hash(form.new_pass.data)
                db.session.commit()
                return redirect(url_for('profile'))

    elif request.method == 'GET':
        return render_template('change_password.html', form=form)
Example #11
0
def change_pass():
    form = ChangePassForm()
    error = False
    if request.method == 'POST' and form.validate():
        m = hashlib.md5()
        m.update(form.old_password.data)
        user = database.get_user(username=current_user.username,
                                 password=m.hexdigest())
        if user is not None:
            m = hashlib.md5()
            m.update(form.password.data)
            user = database.update_user(username=current_user.username,
                                        password=m.hexdigest())
            return redirect(url_for("change_pass_success"))
        error = True
    return render_template("accounts/password_change_form.html",
                           form=form,
                           error=error)
Example #12
0
def userpref_page():
    '''
    Dashbaord User Preferences:
    This will allow a user to change user preferences, i.e. Password
    '''
    verify = verifyLogin(
        app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
    if verify:
        user = User()
        user.config = app.config
        user.get('uid', verify, g.rdb_conn)
        data = startData(user)
        data['active'] = 'dashboard'
        if user.status != "active":
            data['url'] = '/dashboard/mod-subscription'
            tmpl = 'member/mod-subscription.html'
        else:
            # Start processing the change password form
            form = ChangePassForm(request.form)
            if request.method == 'POST':
                if form.validate():
                    result = user.checkPass(form.old_password.data, g.rdb_conn)
                    if result:
                        update = user.setPass(form.password.data, g.rdb_conn)
                        if update:
                            print("/dashboard/user-preferences - Password changed")
                            flash('Password successfully changed.', 'success')
                        else:
                            print("/dashboard/user-preferences - \
                                  Password change failed")
                            flash('Password change was unsuccessful.', 'danger')
                    else:
                        print("/login - User change password error: wrong old password")
                        flash('Old password does not seem valid.', 'danger')
            data['url'] = '/dashboard/user-preferences'
            tmpl = 'member/user-preferences.html'
        page = render_template(tmpl, data=data, form=form)
        return page
    else:
        flash('Please Login.', 'warning')
        return redirect(url_for('user.login_page'))
Example #13
0
def userpref_page():
    '''
    Dashbaord User Preferences:
    This will allow a user to change user preferences, i.e. Password
    '''
    verify = verifyLogin(
        app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
    if verify:
        user = User()
        user.get('uid', verify, g.rdb_conn)
        data = startData(user)
        data['active'] = 'dashboard'
        if user.status != "active":
            data['url'] = '/dashboard/mod-subscription'
            tmpl = 'member/mod-subscription.html'
        else:

            # Start processing the change password form
            form = ChangePassForm(request.form)
            if request.method == 'POST':
                if form.validate():
                    result = user.setPass(form.password.data, g.rdb_conn)
                    if result:
                        data['msg'] = "Password successfully changed"
                        print("/dashboard/user-preferences - Password changed")
                        data['error'] = False
                    else:
                        data['msg'] = "Password change was unsuccessful"
                        print("/dashboard/user-preferences - Password change failed")
                        data['error'] = True
            data['url'] = '/dashboard/user-preferences'
            tmpl = 'member/user-preferences.html'
        page = render_template(tmpl, data=data, form=form)
        return page
    else:
        return redirect(url_for('user.login_page'))