def signup(): ''' User Sign up page: Very basic email + password sign up form that will also login users. ''' ## Data is used throughout for the jinja2 templates data={ 'active': "signup", # Sets the current page 'loggedin': False # Don't show the logout link } ## Define the SignupForm form = SignupForm(request.form) ## Validate and then create userdata if request.method == "POST": if form.validate(): ## Take form data email = form.email.data password = form.password.data company = form.company.data contact = form.contact.data userdata = { 'username': email, 'email': email, 'password': password, 'company': company, 'contact': contact } ## Create user user = User() result = user.createUser(userdata, g.rdb_conn) ## Check results for success or failure if result == "exists": data['error'] = True data['msg'] = 'User already exists' elif result is not False: stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' User Signup', 1) print("/signup - New user created") cdata = cookies.genCdata(result, app.config['SECRET_KEY']) data['loggedin'] = True data['msg'] = 'You are signed up' data['error'] = False ## Build response resp = make_response(redirect(url_for('dashboard_page'))) timeout = int(time.time()) + int(app.config['COOKIE_TIMEOUT']) ## Set the cookie secure as best as possible resp.set_cookie('loggedin', cdata, expires=timeout, httponly=True) return resp else: stathat.ez_count(app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' Failed User Signup', 1) print("/signup - Failed user creation") data['msg'] = 'Form is not valid' data['error'] = True ## Return Signup Page return render_template('signup.html', data=data, form=form)
def signup(): """ User Sign up page: Very basic email + password sign up form that will also login users. """ # Data is used throughout for the jinja2 templates data = {"active": "signup", "loggedin": False} # Sets the current page # Don't show the logout link # Define the SignupForm form = SignupForm(request.form) # Validate and then create userdata if request.method == "POST": if form.validate(): # Take form data email = form.email.data password = form.password.data company = form.company.data contact = form.contact.data userdata = {"username": email, "email": email, "password": password, "company": company, "contact": contact} # Create user user = User() user.config = app.config result = user.createUser(userdata, g.rdb_conn) # Check results for success or failure if result == "exists": flash("User already exists.", "danger") elif result is not False: try: stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " User Signup", 1) except: pass print("/signup - New user created") cdata = cookies.genCdata(result, app.config["SECRET_KEY"]) data["loggedin"] = True flash("You are signed up.", "success") # Generate confirmation token generate_confirmation_token(email, result, time.time()) # Build response resp = make_response(redirect(url_for("member.dashboard_page"))) timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"]) # Set the cookie secure as best as possible resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True) return resp else: stathat.ez_count(app.config["STATHAT_EZ_KEY"], app.config["ENVNAME"] + " False User Signup", 1) print("/signup - False user creation") flash("Form is not valid.", "danger") # Return Signup Page return render_template("user/signup.html", data=data, form=form)
def login_page(): ''' User login page: This is a basic login page''' data = { 'active': 'login', 'loggedin': False } # Define and Validate the form form = LoginForm(request.form) if request.method == "POST": if form.validate(): email = form.email.data password = form.password.data # Start user definition user = User() if user.get('username', email, g.rdb_conn): result = user.checkPass(password, g.rdb_conn) if result is True: data['loggedin'] = True data['msg'] = 'You are logged in' data['error'] = False print("/login - User login successful") # Start building response resp = make_response( redirect(url_for('member.dashboard_page'))) cdata = cookies.genCdata( user.uid, app.config['SECRET_KEY']) timeout = int(time.time()) + \ int(app.config['COOKIE_TIMEOUT']) # Set cookie as securely as possible resp.set_cookie( 'loggedin', cdata, expires=timeout, httponly=True) print("Setting cookie") return resp else: data['msg'] = 'Password does not seem valid' data['error'] = True print("/login - User login error: wrong password") else: data['msg'] = 'Uhh... User not found' print("/login - User login error: invalid user") data['error'] = True else: data['msg'] = 'Form is not valid' print("/login - User login error: invalid form") data['error'] = True # Return Login Page page = render_template('user/login.html', data=data, form=form) return page
def login_page(): ''' User login page: This is a basic login page''' data = {'active': 'login', 'loggedin': False} # Define and Validate the form form = LoginForm(request.form) if request.method == "POST": if form.validate(): email = form.email.data password = form.password.data # Start user definition user = User() if user.get('username', email, g.rdb_conn): result = user.checkPass(password, g.rdb_conn) if result is True: data['loggedin'] = True data['msg'] = 'You are logged in' data['error'] = False print("/login - User login successful") # Start building response resp = make_response( redirect(url_for('member.dashboard_page'))) cdata = cookies.genCdata(user.uid, app.config['SECRET_KEY']) timeout = int(time.time()) + \ int(app.config['COOKIE_TIMEOUT']) # Set cookie as securely as possible resp.set_cookie('loggedin', cdata, expires=timeout, httponly=True) print("Setting cookie") return resp else: data['msg'] = 'Password does not seem valid' data['error'] = True print("/login - User login error: wrong password") else: data['msg'] = 'Uhh... User not found' print("/login - User login error: invalid user") data['error'] = True else: data['msg'] = 'Form is not valid' print("/login - User login error: invalid form") data['error'] = True # Return Login Page page = render_template('user/login.html', data=data, form=form) return page
def login_page(): """ User login page: This is a basic login page""" data = {"active": "login", "loggedin": False} # Define and Validate the form form = LoginForm(request.form) if request.method == "POST": if form.validate(): email = form.email.data password = form.password.data # Start user definition user = User() user.config = app.config if user.get("username", email, g.rdb_conn): result = user.checkPass(password, g.rdb_conn) if result is True: data["loggedin"] = True print("/login - User login successful") flash("You are logged in.", "success") # Start building response resp = make_response(redirect(url_for("member.dashboard_page"))) cdata = cookies.genCdata(user.uid, app.config["SECRET_KEY"]) timeout = int(time.time()) + int(app.config["COOKIE_TIMEOUT"]) # Set cookie as securely as possible resp.set_cookie("loggedin", cdata, expires=timeout, httponly=True) print("Setting cookie") return resp else: print("/login - User login error: wrong password") flash("Password does not seem valid.", "danger") else: print("/login - User login error: invalid user") flash("Uhh... User not found.", "danger") else: print("/login - User login error: invalid form") flash("Form is not valid.", "danger") # Return Login Page return render_template("user/login.html", data=data, form=form)
def signup(): ''' User Sign up page: Very basic email + password sign up form that will also login users. ''' # Data is used throughout for the jinja2 templates data = { 'active': "signup", # Sets the current page 'loggedin': False # Don't show the logout link } # Define the SignupForm form = SignupForm(request.form) # Validate and then create userdata if request.method == "POST": if form.validate(): # Take form data email = form.email.data password = form.password.data company = form.company.data contact = form.contact.data userdata = { 'username': email, 'email': email, 'password': password, 'company': company, 'contact': contact } # Create user user = User() user.config = app.config result = user.createUser(userdata, g.rdb_conn) # Check results for success or failure if result == "exists": flash('User already exists.', 'danger') elif result is not False: try: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' User Signup', 1) except: pass print("/signup - New user created") cdata = cookies.genCdata(result, app.config['SECRET_KEY']) data['loggedin'] = True flash('You are signed up.', 'success') # Generate confirmation token generate_confirmation_token(email, result, time.time()) # Build response resp = make_response(redirect(url_for('member.dashboard_page'))) timeout = int(time.time()) + int(app.config['COOKIE_TIMEOUT']) # Set the cookie secure as best as possible resp.set_cookie( 'loggedin', cdata, expires=timeout, httponly=True) return resp else: stathat.ez_count( app.config['STATHAT_EZ_KEY'], app.config['ENVNAME'] + ' False User Signup', 1) print("/signup - False user creation") flash('Form is not valid.', 'danger') # Return Signup Page return render_template('user/signup.html', data=data, form=form)