def register(): form = RegisterForm() if form.validate_on_submit(): username = form.username.data email = form.email.data password = form.password.data confirm_password = form.confirm_password.data # Create a key for email activation activation_key = str(uuid4()) # Store the key for the username to Redis with 24hr expiration redis_conn.set(f"activation_key_{username}", activation_key, ex=24 * 60 * 60) if password == confirm_password: add_user(username=username, password=password, email=email) # Send a confirmation mail and ask for activation msg = Message("EDA Miner: Account created", recipients=[email]) msg.html = ("To activate your account (within 24 hours) visit" f" <a href='http://127.0.0.1:8000/activate" f"/{username}/{activation_key}'>this page</href>." f" Note that you need to confirm your account to" f" use the app and get an API token.") mail.send(msg) return "Check your inbox (or spam) for the confirmation message." return render_template("register.html", form=form)
def sucess(n_clicks, input1, input2, input3, input4): existing_user = User.query.filter_by(username=input1).first() if input3 != input4: return None, "Different Password." if existing_user is None: add_user(input1, input3, input2, 0) if tokenMake(input2): print('A confirmation email has been sent via email.', 'success') return '/login', None else: return None, "Internal Server Error {0}." return None, "A user already exists with that email address." else: return None, "Exist user!"
def signup(n_clicks, name, email, password): um.create_user_table() # username, password, email if name and password and email: try: um.add_user(name, password, email) except: pass user = User.query.filter_by(username=name).first() if check_password_hash(user.password, password): login_user(user) return '/success' else: pass else: pass
def createUser(n_clicks, usernameSubmit, newPassword1Submit, newPassword2Submit, newEmailSubmit, pageContent, newUser, newPassword1, newPassword2, newEmail, admin): if (n_clicks > 0) or (usernameSubmit > 0) or (newPassword1Submit > 0) or \ (newPassword2Submit > 0) or (newEmailSubmit > 0): if newUser and newPassword1 and newPassword2 and newEmail != '': if newPassword1 == newPassword2: if len(newPassword1) > 3: try: add_user(newUser, newPassword1, newEmail, bool(admin)) return html.Div(children=['New User created'], className='text-success') except Exception as e: return html.Div(children=['New User not created: {e}'.format(e=e)], className='text-danger') else: return html.Div(children=['New Password Must Be Minimum 4 Characters'], className='text-danger') else: return html.Div(children=['Passwords do not match'], className='text-danger') else: return html.Div(children=['Invalid details submitted'], className='text-danger')
import users_mgt as um um.create_user_table() um.add_user('krishna','krishna','*****@*****.**') um.show_users() um.del_user('test')
from app_extensions import db import os if __name__ == "__main__": if os.path.exists("users.db"): os.remove("users.db") flask_app.config.update(config) db.init_app(flask_app) with flask_app.app_context() as ctx: # Create the database db.create_all() # Add dummy users add_user(username="******", password="******", superuser=True, email=env_config_get("MAIL_USERNAME")) add_user(username="******", password="******", superuser=False, email="*****@*****.**") # Allow admin to use all apps permit_user_app("admin", "data") permit_user_app("admin", "visualization") permit_user_app("admin", "modeling") # Allow example to use only two apps permit_user_app("example", "data") permit_user_app("example", "visualization")
#!/usr/bin/env python # coding: utf-8 # In[1]: import users_mgt as um # In[2]: um.create_user_table() # In[4]: um.add_user('test2', 'test2', '*****@*****.**') # In[7]: um.show_users() # In[6]: um.del_user('test') # In[ ]: