def signup(): ''' This function inserts a new user to the database. The user need to wait for admin approval ''' form = SignUpForm() if request.method == 'POST' and form.validate(): """ u = User( form.username.data, form.first_name.data, form.last_name.data, form.email.data, form.password.data ) """ password = ''.join(random.choice(string.ascii_letters+string.digits) for x in range(5)) u = User( username = form.username.data, first_name = form.first_name.data, last_name = form.last_name.data, email = form.email.data, password = password ) db.session.add(u) db.session.commit() msg = "Your account password is %s. Please login and change your password." % password flash(msg) #return redirect(url_for('home')) return render_template('tmp_home.html', password=password) # this executes if GET request return render_template('signup.html', form=form)
def signup(): if 'email' in session: return redirect(url_for("home")) form = SignUpForm() if request.method == 'POST': if form.validate() == False: print("Validation failed") return render_template("signup.html", form=form) else: newuser = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data) db.session.add(newuser) try: db.session.commit() except: db.session.rollback() return render_template( "signup.html", form=form, error='This email id alrady exists in the database') session['email'] = newuser.email print("New user email:" + newuser.email + " and password :"******"signup.html", form=form)
def signup(): form = SignUpForm() if 'rollno' in session: return redirect(url_for('profile')) if request.method == 'POST': if form.validate() == False: return render_template('signup.html', form = form ) else: user = User(request.form['rollno'] , request.form['password'],request.form['email'],request.form['room_no'],request.form['hostel']) db.session.add(user) db.session.commit() session['rollno'] = user.rollno print user.rollno print 'F**k this shit' return redirect(url_for('profile')) elif request.method == 'GET': return render_template('signup.html', form = form )
def signup(): error = None form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): user = User.query.filter_by(email=form.email.data).first() if user is None: # User db structure (email, password) email = form.email.data password = form.password.data user = User(email, password) db.session.add(user) db.session.commit() # send_signup_email() message = 'You have successfully signed up for Terml.io.' session['logged_in'] = True session['email'] = user.email session['username'] = '' for letter in user.email: if letter != '@': session['username'] += letter elif letter == '@': break session['is_active'] = user.is_active session['expiration_date'] = user.expiration_date return render_template('index.html', message=message) error = 'That email is already being used by another account. Please sign in, or use a different email.' return render_template('signup.html', form=form, error=error) return render_template('signup.html', form=form)
def signup(): form = SignUpForm(request.form) if request.method == "POST": if form.validate(): username = form.username.data email = form.email.data password = form.password.data connection = pymongo.Connection(CONNECTION_STRING, safe=True) message = {"error": None} if not user.newuser(connection[DATABASE], username, email, password, message): pigeon.error(message["error"]) else: pigeon.success(u"Welcome to Office! Your local gist!") # Set cookies to client. session_id = user.start_session(connection[DATABASE], username) cookie = user.make_secure_val(session_id) redirect_to_home = redirect_back("index") response = app.make_response(redirect_to_home) response.set_cookie(COOKIE, value=cookie) # Mark this user has logged in. session["logged_in"] = True session["username"] = username return response return render_template("signup.html", form=form, status="signup")
def register(): form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): user = User(email=form.email.data, password=form.password.data) user.save() flash('Thanks for registering') return redirect(url_for('pages.home')) return render_template('register.html', form=form)
def sign_up(): errors = [] form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): # looks like everything ok, check db username = form.username.data password = form.password.data user = list(User.view('users/by_username', key=username)) if user: errors.append('User already exists') else: new_user = make_user_from_request(request) g.db.save_doc(new_user) flash('You have successfully registered') return redirect(url_for('show_posts')) elif request.method == 'POST' and not form.validate(): errors.extend(format_form_errors(form.errors.items())) return render_template('sign_up.html', form = form, errors = errors)
def signup(): if request.method == 'POST': form = SignUpForm(request.form) if form.validate(): user = form.save_entry() db.session.add(user) db.session.commit() flash('User %s created Successfully! Please Login'% user.name,'success') return redirect(url_for('login')) else: form = SignUpForm() return render_template('signup.html',form = form)
def signup(): """ Signup a new user """ form = SignUpForm(request.form) if not request.method == 'POST' or not form.validate(): context = {'form': form} return render_template('signup.html', **context) username = form.username.data password = form.password.data email = form.email.data phone = form.phone.data address = form.address.data subscribe = form.subscribe.data duration = form.duration.data pay_method = form.pay_method.data # Check if they they exist already try: user = User.objects.get(username=username) except User.DoesNotExist: try: user = User.objects.get(email=email) except User.DoesNotExist: user = User(username=username, email=email) user.address = address user.phone = phone user.address = address user.subscribe = subscribe user.set_password(password) try: local = geocode(user.address) user.location = [float(local['lat']), float(local['lng'])] except Exception, e: pass try: user.save() except Exception, e: print e else: # Place holder until paid subscription enabled if pay_method == 'free': duration = 2 expires = datetime.today() + relativedelta(months=2) subscription = Subscription(user=user, expires=expires, active=True) subscription.save()
def signup(): form = SignUpForm() if request.method == 'POST' and form.validate(): u = User(user_name=form.username.data, first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=form.password.data) db.session.add(u) db.session.commit() session['email'] = u.email return redirect(url_for('home')) return render_template('signup.html', form=form)
def signup_page(): form = SignUpForm() if request.method == 'GET': return render_template('signup.html', form=form) if request.method == 'POST' and form.validate() and sessions.validate_new_user(form.login.data, form.password.data, form.confirm.data, form.secret.data): if sessions.new_user(form.login.data, form.password.data): user = User.objects(username=form.login.data).first() login_user(user) return redirect(url_for('index')) else: return redirect(url_for('signup_page')) else: return redirect(url_for('signup_page'))
def post(self): data = json.decode(self.request.body) form = SignUpForm(**data) if not form.validate(): return ResponseBadRequest(form.errors) created, user = self.user_model.create_user(form.email.data, email=form.email.data, password_raw=form.password.data, full_name=form.full_name.data) if not created: return ResponseBadRequest('Unable to create user. This email address is already exists') user_dict = self.auth.store.user_to_dict(user) self.auth.set_session(user_dict, remember=True) # store user data in the session return Response(user_dict)
def signup(): if current_user.is_authenticated: return render_view(url_for('dashboard'), redirect=True, message=_('SESSIONS_MSG_ALREADY_SIGNED_IN')) redirect_to = session.pop('redirect_to', None) if request.values.get('ret'): redirect_to = request.values.get('ret') form = SignUpForm(ret=redirect_to) if form.is_submitted(): try: if not form.validate(): raise Exception(_('ERROR_INVALID_SUBMISSION')) if not verify_captcha(): raise Exception(_('SESSIONS_ERROR_UNFINISHED_CHALLENGE_LBL')) # Create user from the form user = User.create() form.populate_obj(user) user.set_password(form.password.data) user.last_seen = datetime.datetime.utcnow() user.last_login = datetime.datetime.utcnow() # store the user user.save() # Login User login_user(user) redirect_to = form.back_link.data if not redirect_to: redirect_to = url_for('dashboard') # send registration email send_email('registration', user) return render_view(redirect_to, redirect=True, message=_('SESSIONS_MSG_SIGNUP_COMPLETED')) except Exception as e: flash(e.message, 'error') return render_view('admin/sessions/signup.html', form=form)
def signup(): # dans le cas ou l'utilisateur accede par l'url /signup en etant connecté if 'session_on' in session and session['session_on']: flash('Deconnectez vous pour inscrire un nouveau compte', category='info') return redirect('/') # formulaire WTForm form = SignUpForm(request.form) cursor = connexion.cursor() # envoie du formulaire if request.method == 'POST' and form.validate(): email = form.email.data # encryption du mot de passe password = sha256_crypt.encrypt((str(form.password.data))) query = "SELECT * FROM users WHERE email LIKE (%s)" response = cursor.execute(query, email) connexion.commit() cursor.close() # verifie si le courriel existe deja if int(response) > 0: flash("Cette adresse courriel existe deja", category='warning') return render_template('signup.html', form=form) # creation du nouveau compte else: cursor = connexion.cursor() query = "INSERT INTO users (email, password) VALUES ( %s, %s)" cursor.execute(query, (email, password)) connexion.commit() userId = cursor.lastrowid cursor.close() flash("Votre nouveau compte est inscris", category='success') cursor.close() session['idUser'] = userId session['session_on'] = True session['email'] = email return redirect('/') return render_template('signup.html', form=form)
def signup(): if 'username' in session: return redirect(url_for('panel')) form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): try: user = User(form.username.data, form.email.data, form.phone.data, form.name.data, form.password.data) db.session.add(user) db.session.commit() mailaddress = form.email.data server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.login("untitledchannelx", mailpassword) msg = MIMEMultipart('alternative') msg['Subject'] = "ChannelX: Account Verification" msg['From'] = "*****@*****.**" msg['To'] = mailaddress html = """\ <html> <head></head> <body> <h1>ChannelX</h1> <p>Welcome our family! Please <a href="http://*****:*****@gmail.com", mailaddress, msg.as_string()) server.close() except IntegrityError: flash('Already signed up user!', 'warning') return render_template('signup.html', form=form) flash("Thanks for registering, we've sent email for validation", 'info') return redirect(url_for('login')) return render_template('signup.html', form=form)
def sign_up(): form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.form) if form.validate(): user = User() user.email = form.email.data user.set_password(form.password.data) user.save() if login_user(user, remember="no"): flash({'type': 'info', 'text': 'Logged In!'}) else: flash({'type': 'danger', 'text': 'failed to sign in'}) return redirect('/') return render_template("/auth/sign-up.html", **locals())
def signup(): form = SignUpForm() if request.method == 'POST' and form.validate(): u = User( user_name = form.username.data, first_name = form.first_name.data, last_name = form.last_name.data, email = form.email.data, password = form.password.data ) db.session.add(u) db.session.commit() session['email'] = u.email return redirect(url_for('home')) return render_template('signup.html', form=form)
def sign_up(): form = SignUpForm() if request.method == 'POST': form = SignUpForm(request.form) if form.validate(): user = User() user.email = form.email.data user.set_password(form.password.data) user.save() if login_user(user, remember="no"): flash({'type': 'info', 'text': 'Logged In!'}) else: flash({'type': 'danger', 'text': 'failed to sign in'}) return redirect('/') return render_template("/auth/sign-up.html", **locals())
def sign_up(): sign_up_form = SignUpForm(request.form) if request.method == 'POST': if sign_up_form.validate(): login = sign_up_form.login.data password = sign_up_form.password.data session['login'] = login user = User(login, password) db.session.add(user) db.session.commit() return redirect(url_for('shortener')) else: return render_template('sign_up.html', form=sign_up_form) elif request.method == 'GET': return render_template('sign_up.html', form=sign_up_form)
def post(self): form = SignUpForm() if form.validate(): if session.query(User).filter_by(nickname=form.nickname.data).count() == 0: session.add(User(nickname=form.nickname.data, password=form.password.data)) session.commit() msg = 'Thanks for registering <strong class=badge>{0}</strong>. \ Please sign in'.format(form.nickname.data) flash(msg) return redirect(url_for('login')) else: msg = 'User <strong class=badge>{0}</strong> already \ exists.'.format(form.nickname.data) flash(msg) return render_template('signup.haml', form=form)
def sign_up(): sign_up_form = SignUpForm(request.form) if request.method == 'POST': if sign_up_form.validate(): login = sign_up_form.login.data password = sign_up_form.password.data session['login'] = login user = User(login, password) db.session.add(user) db.session.commit() return redirect(url_for('shortener')) else: return render_template('sign_up.html', form=sign_up_form) elif request.method == 'GET': return render_template('sign_up.html', form=sign_up_form)
def SignUp(): if 'email' in session: return redirect(url_for('home')) form = SignUpForm() if (request.method == 'POST'): if form.validate() == False: return render_template('signup.html', form=form) else: new_user = User(form.f_name.data, form.l_name.data, form.email.data, form.passwd.data) db.session.add(new_user) db.session.commit() session['email'] = new_user.email return redirect(url_for('home')) elif (request.method == 'GET'): return render_template('signup.html', form=form)
def signup(): data = MultiDict(mapping = request.json) inputs = SignUpForm(data , csrf_enabled=False) if not inputs.validate(): return bad_request_error(inputs.errors) else: data = request.get_json() firstname = data['firstname'] lastname = data['lastname'] email = data['email'] password = data['password'] user = User(firstname , lastname , email , password) db.session.add(user) db.session.commit() response = jsonify(user.__repr__()) response.status_code = 201 return response
def sign_up(): data = MultiDict(mapping=request.json) inputs = SignUpForm(data, csrf_enabled=False) if not inputs.validate(): return bad_request_error(inputs.errors) else: data = request.get_json() firstname = data['firstname'] lastname = data['lastname'] email = data['email'] password = data['password'] user = User(firstname, lastname, email, password) db.session.add(user) db.session.commit() response = jsonify(user.__repr__()) response.status_code = 201 return response
def signup(): if 'email' in session: return redirect(url_for('home')) else: form = SignUpForm() if request.method == 'POST': if not form.validate(): return render_template('signup.html', form=form) else: user = User(form.first_name.data, form.last_name.data, form.email.data, form.password.data) db.session.add(user) db.session.commit() session['email'] = user.email return redirect(url_for('home', )) else: return render_template('signup.html', form=form)
def signup(): from forms import SignUpForm from db_classes import UsersDiary signup_form = SignUpForm(request.form) if request.method == "POST" and signup_form.validate(): username = signup_form.username.data email = signup_form.email.data password = signup_form.password.data key = Fernet.generate_key() UsersDiary.insert({ UsersDiary.username: username, UsersDiary.password: sha256_crypt.hash(password), UsersDiary.email: email, UsersDiary.key: key }).execute() flash("You have registered successfully.", "success") return redirect(url_for("index")) return render_template("signup.html", signup_form=signup_form)
def signup(): signupform = SignUpForm() if request.method == 'POST' and signupform.validate(): data = { u"name": request.form['name'], u"email": request.form['email'], u"password": request.form['password'] } try: user = auth.create_user_with_email_and_password( data["email"], data["password"]) except: return render_template( 'signup.html', form=signupform, wrong="Either your email or password were incorrect.") db_data = { u"name": request.form['name'], u"email": request.form['email'], } email = request.form['email'].replace('@', '').replace('.', '') db.child(email).set(db_data) key = db.child(email).child("posts").push({ u"title": u"Example Post", u"date": u"10/30/2019", u"content": u"You can write out your thoughts and feelings here!", }) db.child(email).child("posts").child( key["name"]).child("comments").push({ u"name": u"Name [Therapist]", u"title": u"Example Comment", u"content": u"Your therapist can comment here!" }) session["email"] = email session["name"] = data["name"] return redirect(url_for("patient_dashboard")) return render_template('signup.html', form=signupform, wrong="")
def signup(): """ Signup a new user """ form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): first_name = form.first_name.data last_name = form.last_name.data username = form.username.data password = form.password.data preference = form.preference.data phone = form.phone.data address = form.address.data # Check if they they exist already try: user = User.objects.get(username=username) except User.DoesNotExist: user = User(username=username) user.first_name = first_name user.last_name = last_name user.address = address user.phone = phone user.address = address user.preference = preference user.set_password(password) try: local = geocode(user.address) user.location = [float(local['lat']), float(local['lng'])] except Exception as e: pass try: user.save() except Exception as e: print(e) else: form.username.errors = "User already exists" context = {'form': form} content = render_template('signup.html', **context) return content
def sign_up(): form = SignUpForm(csrf_enabled=False) if request.method == "GET": return render_template("signup.html", form=form) elif request.method == "POST": if not form.validate(): return render_template("signup.html", form=form) else: num = g.conn.execute('''SELECT COUNT(person_id) FROM people''') p_id = num.fetchone()[0] p_id = p_id + 1 g.conn.execute( '''INSERT INTO people (person_id, name, email, race, current_city, pronouns, password) VALUES ( (%s),(%s),(%s),(%s),(%s),(%s),(%s))''', p_id, form.name.data, form.email.data, form.race.data, form.city.data, form.pronouns.data, form.password.data) return render_template("dashboard.html", form=form)
def signup(): form = SignUpForm(request.form) if 'email' in session: return redirect(url_for('profile')) if request.method == 'POST': if form.validate() == False: return render_template('signup.html', form=form) else: new_user = User(form.firstname.data, form.lastname.data, form.email.data, form.password.data) db.session.add(new_user) db.session.commit() session['email'] = new_user.email return redirect(url_for('profile')) return render_template('signup.html', form=form)
def signup(): form = SignUpForm() if request.method == 'POST': if form.validate() == False: flash ("Wow, that didn't work!") return render_template('signup.html', form=form) else: newuser = User(form.firstname.data, form.lastname.data, form.username.data, form.password.data) db.session.add(newuser) db.session.commit() # hashes the username as an ecrypted ID and stores as a cookie in the user's browser session['username'] = newuser.username user = User.query.filter_by(username = form.username.data.lower()).first() session['userID'] = user.userID return redirect(url_for('profile')) elif request.method == 'GET': return render_template('signup.html', form=form,communityform=CreateCommunityForm())
def signup(): form = SignUpForm() if request.method == 'POST': if form.validate() == False: flash('All fields are required.') return render_template('signup.html', form=form, page="signup") else: msg = Message('Sign up request', sender=appconfig.MailData.FROM, recipients=appconfig.MailData.TO) msg.body = "" msg.html = render_template('signup_email.html', fname=form.fname.data, lname=form.lname.data, skype=form.skype.data, username=form.username.data, \ email=form.email.data, password=form.password.data, repassword=form.repassword.data, account_type=form.account_type.data) try: mail.send(msg) return render_template('signup.html', success=True, page="signup") except: form = SignUpForm() return render_template('signup.html', form=form, error=True, page="signup") elif request.method == 'GET': return render_template('signup.html', form=form, success=None, page="signup")
def signup(): """ Signup a new user """ if request.method == 'GET': form = SignUpForm(obj=current_user) else: form = SignUpForm(request.form) if request.method == 'POST' and form.validate(): email = form.email.data password = form.password.data # Check if they they exist already user = Users.get_one(email=email) if not user: email = form.email.data first_name = form.first_name.data last_name = form.last_name.data user = User( **{ 'email': email, 'first_name': first_name, 'last_name': last_name }) user.set_password(password) user.provider_type = form.provider_type.data user.practice_name = form.practice_name.data user.practice_type = form.practice_type.data try: user.save() except Exception as e: log.exception(f"Exception trying to save user {email}") else: return redirect('/') else: form.errors = "User already exists" context = {'form': form} content = render_template('signup.html', **context) return content
def login(): """For GET requests, display the login form. For POSTS, login the current user by processing the form.""" login_form = LoginForm(request.form) signup_form = SignUpForm(request.form) if request.method == 'POST': if 'email' not in request.form and login_form.validate(): usuario = db.session.query(User).filter_by( username=str(login_form.username.data)).first() if usuario: if login_form.password.data == usuario.password: login_user(usuario) usuario.authenticated = True db.session.commit() # 'next = flask.request.args.get('next') # next_is_valid should check if the user has valid # permission to access the `next` url # if not next_is_valid(next): # return flask.abort(400) # return flask.redirect(next or flask.url_for('index')) return "Success" else: return "Contraseña incorrecta" else: return "Usuario no existe" elif signup_form.validate(): db.session.add( User(signup_form.username.data, signup_form.email.data, signup_form.password.data, signup_form.name.data, True) ) db.session.commit() return render_template('login.html', login_form=login_form, signup_form=signup_form)
def sign_up(): if 'email' in session: return redirect(url_for('contacts')) form = SignUpForm() if request.method == 'POST': if form.validate() is False: flash('Please fill out the form completely') return render_template('Signup.html', form=form) else: if db_session.query(User).filter_by(email=form.email.data).first(): flash('Email already in use') return render_template('Signup.html', form=form) else: pw_hash = bcrypt.generate_password_hash(form.password.data) users = User(form.first_name.data, form.last_name.data, pw_hash, form.email.data) db_session.add(users) db_session.commit() session['email'] = form.email.data return redirect(url_for('contacts')) elif request.method == 'GET': return render_template('Signup.html', form=form)
def index(): if current_user.is_authenticated: return redirect(url_for('profile') + ('/' + current_user.slug)) else: formS = SignUpForm(request.form) if request.method == 'POST': formS = SignUpForm(request.form) user_name = User.objects(name=formS.name.data) user_email = User.objects(email=formS.email.data) if formS.validate() == False: flash('Something went wrong', 'danger') return render_template('index.html', form=formS) if formS.validate_on_submit(): password = formS.password.data password_hash = sha256_crypt.encrypt(password) form_email = formS.email.data if not Email_Regex.match(form_email): flash('Invalid email adress', 'danger') return render_template("index.html", form=formS, title="Copylighter", regex="Invalid email adress") else: pass newuser = User(name=formS.name.data, email=formS.email.data, password=password_hash) try: newuser.save() except NotUniqueError: if user_name and user_email: flash('Username or Email is already taken', 'danger') return render_template("index.html", form=formS, title="Copylighter", regex="Already taken") elif user_email: flash('Username or Email is already taken', 'danger') return render_template("index.html", form=formS, title="Copylighter", regex_email="Already taken") elif user_name: flash('Username or Email already taken', 'danger') return render_template("index.html", form=formS, title="Copylighter", regex_name="Already taken") else: pass flash('Successfully registered. You can login now', 'success') return redirect(url_for('login')) else: return render_template("index.html", form=formS, title="Copylighter") return render_template("index.html", form=formS, title="Copylighter")