def edit_profile(user_id): if request.method == "GET": return render_template("auth/edit.html", form = EditForm(), user = User.query.get(user_id), tasks = User.users_tasks(user_id), count = len(User.users_tasks(user_id))) user = User.query.get(user_id) form = EditForm(request.form) if not form.validate(): return render_template("auth/edit.html", form = form, user = User.query.get(user_id), tasks = User.users_tasks(user_id), count = len(User.users_tasks(user_id))) if user.username != form.username.data: found_user = User.query.filter_by(username = form.username.data).first() if found_user: return render_template("auth/edit.html", form = form, user = User.query.get(user_id), tasks = User.users_tasks(user_id), count = len(User.users_tasks(user_id)), error = "Username already exists") user.username = form.username.data user.role = form.role.data db.session().commit() return redirect(url_for("users_index"))
def profile_edit(id): #GET user = current_user if request.method == "GET": form = EditForm(obj=user) return render_template("auth/edit.html", form=form, user_id=id) #POST form = EditForm(request.form) if not form.validate(): return render_template("auth/edit.html", form=form, user_id=id, error="Something went wrong!") if str(user.password) != str(form.old_password.data): return render_template( "auth/edit.html", form=form, user_id=id, error="Old password didn't match with the given password!") user.name = form.name.data user.username = form.username.data user.password = form.new_password.data db.session().commit() return redirect(url_for("profile_look"))
def auth_modify(): form = EditForm(request.form) if not form.validate(): return render_template("auth/editform.html", form=form) u = User.query.get(current_user.id) u.name = form.name.data u.username = form.username.data u.password = form.password.data u.iban = form.iban.data db.session().add(u) db.session().commit() return redirect(url_for("courses_index"))
def edit_user_save(profile_id): form = EditForm(request.form) user = User.query.get(profile_id) if (current_user.id != user.id and current_user.role.name != "ADMIN" ) or current_user.role.name is "ADMIN": error = "Voit muokata vain omaa profiilia." return render_template("profile/edit.html", authError=error) if current_user.role.name != "ADMIN": form.roles.data = str(user.roles) if not form.validate(): return render_template("profile/edit.html", form=form, profile=user) user.name = form.name.data user.username = form.username.data if form.newPassword.data: if user.password != form.oldPassword.data: form.oldPassword.errors.append("Väärä salasana") return render_template("profile/edit.html", form=form, profile=user) if form.newPassword.data != form.newPasswordAgain.data: form.newPassword.errors.append("Salasanat eivät täsmää") return render_template("profile/edit.html", form=form, profile=user) if len(form.newPassword.data) < 6 or len(form.newPassword.data) > 30: form.newPassword.errors.append( "Uuden salasanan pituuden on oltava vähintään 6 merkkiä ja enintää 30 merkkiä " ) return render_template("profile/edit.html", form=form, profile=user) user.password = form.newPassword.data if current_user.role.name == "ADMIN": user.roles = form.roles.data db.session().commit() return redirect(url_for('view_profile', profile_id=user.id))
def user_own(): groups = Groups.find_owned_groups(current_user.get_id()) discussions = Discussion.find_owned_discussions(current_user.get_id()) form = EditForm() return render_template("users/own.html", groups=groups, discussions=discussions, form=form)
def auth_edit(user_id): form = EditForm() user = User.query.get(user_id) role = Role.query.filter_by(account_id=user_id).first() if role == None: rolename = "USER" else: rolename = role.name form.role.choices = [('USER', 'Regular'), ('ADMIN', 'Adminstrator')] form.role.default = rolename form.process() return render_template("auth/edit_user.html", user=user, form=form, rolename=rolename)
def edit_user_save(profile_id): form = EditForm(request.form) user = User.query.get(profile_id) if current_user.role.name != "ADMIN": form.roles.data = str(user.roles) if not form.validate(): return render_template("profile/edit.html", form=form, profile=user) user.name = form.name.data user.username = form.username.data if current_user.role.name == "ADMIN": user.roles = form.roles.data db.session().commit() return redirect(url_for('view_profile', profile_id=user.id))
def user_edit(): form = EditForm(request.form) groups = Groups.find_usernames_for_group_owners() if not form.validate(): e = "Minimum length for name and password is 3" return render_template("index.html", groups=groups, error=e) p1 = request.form.get("password_new1") p2 = request.form.get("password_new2") pold = request.form.get("password_old") old = Account.query.filter_by(id=current_user.get_id()).first() if old.password == pold: if p1 == p2: Account.change_password(p1, current_user.get_id()) return redirect(url_for("user_own")) else: e = "Your passwords do not match" else: e = "Your old password was wrong" return render_template("index.html", groups=groups, error=e)
def auth_update(user_id): user = User.query.get(user_id) form = EditForm(request.form) form.role.choices = [('USER', 'Regular'), ('ADMIN', 'Adminstrator')] if not form.validate(): return render_template("auth/edit_user.html", user=user, form=form) user.email = form.email.data rolename = form.role.data #just overwrite existing role instead of utilizing the table structure #for simplified management role = Role.query.filter_by(account_id=user_id).first() if role is not None: if (role.name is not rolename): role.name = rolename else: role = Role(user_id, rolename) db.session.add(role) db.session().commit() return redirect(url_for("administrate_access"))
def user_edit(): user = User.query.get(current_user.id) if request.method == "GET": form = EditForm() form.newusername.data = user.username form.newemail.data = user.email return render_template("auth/editform.html", form=form) form = EditForm(request.form) if not form.validate(): return render_template("auth/editform.html", form=form) user.username = form.newusername.data user.email = form.newemail.data db.session().commit() flash("Changes saved.") return redirect(url_for("user_edit"))
def auth_edit(): if request.method == "GET": return render_template("auth/edit.html", form=EditForm(obj=current_user)) form = EditForm(request.form) if len(form.username.data) < 2: return render_template("auth/edit.html", form=form, error="Username must be at least two characters long") if (form.password_new.data != ""): if (form.password_old.data != current_user.password): return render_template("auth/edit.html", form=form, error="Wrong password!") if (form.password_new.data != form.password_check.data): return render_template("auth/edit.html", form=form, error="New passwords didn't match") current_user.password = form.password_new.data current_user.name = form.name.data current_user.username = form.username.data db.session.commit() return redirect(url_for("index"))
def edit_user(profile_id): user = User.query.get(profile_id) if not user: error = "Profiilia ei löytynyt." return render_template("profile/edit.html", authError=error) if (current_user.id != user.id and current_user.role.name != "ADMIN" ) or current_user.role.name is "ADMIN": error = "Voit muokata vain omaa profiilia." return render_template("profile/edit.html", authError=error) form = EditForm(roles=user.role.id) form.name.data = user.name form.username.data = user.username return render_template("profile/edit.html", form=form, profile=user)
def auth_edit(): return render_template("auth/editform.html", form=EditForm())