def populate_database(): logger.info('Populating user database...') from omf.model.user import User from omf.web import persistence admin = User(username='******', registered=True, password_digest=User.hash_password('admin'), role=Role.ADMIN.value) test = User(username='******', registered=True, password_digest=User.hash_password('test')) persistence.addUser(admin) persistence.addUser(test) logger.info('User database populated.')
def register(email, reg_key): logger.info('Calling /register/%s/%s', email, reg_key) if flask_login.current_user.is_authenticated(): return redirect("/") try: user = persistence.getUser(email) except Exception as e: logger.exception('Registering user, exception...') user = None if not (user and reg_key == user.reg_key and user.timestamp and dt.timedelta(1) > dt.datetime.now() - user.timestamp): return "This page either expired, or you are not supposed to access it. It might not even exist" if request.method == "GET": return render_template("register.html", email=email) password, confirm_password = map( request.form.get, ["password", "confirm_password"]) if password == confirm_password: user.username = email user.password_digest = User.hash_password(password) user.registered = True persistence.updateUser(user) flask_login.login_user(user) return redirect("/")
def changepwd(): old_pwd, new_pwd, conf_pwd = map( request.form.get, ["old_pwd", "new_pwd", "conf_pwd"]) user = persistence.getUser(current_user_name()) if user.verify_password(old_pwd): if new_pwd == conf_pwd: user.password_digest = User.hash_password(new_pwd) persistence.updateUser(user) return "Success" else: return "not_match" else: return "not_auth"