def register(): ''' Register endpoint ''' if current_user.is_authenticated: return redirect(url_for('index')) form_login = LoginForm() form_register = RegisterForm() if form_register.validate_on_submit(): query_email = DB.session.query(User.id).filter_by( email=form_register.email.data).scalar() is not None query_user = DB.session.query(User.id).filter_by( username=form_register.username.data).scalar() is not None if not query_email and not query_user: hashed_password = generate_password_hash( form_register.password.data, method='sha256') new = User(username=form_register.username.data, password=hashed_password, email=form_register.email.data) DB.session.add(new) DB.session.commit() return redirect(url_for('login')) else: flash('Username or Email already exist') return render_template('login.html', form_login=form_login, form_register=form_register)
def register(request): if request.method == 'POST': frm = RegisterForm(request.POST) # frm.cleaned_data # print (frm) # return HttpResponse("efgsb") if frm.is_valid(): fdata = frm.cleaned_data uname = fdata['username'] name = fdata['name'] passwd = fdata['password'] try: print uname, passwd usr = User(username=uname) usr.set_password(passwd) usr.save() except: return HttpResponse("User already exists!") myusr = MyUser(user=usr, name=name, t=0) myusr.save() return render(request, "welcome.html") else: return HttpResponse("fill all the boxes") else: return HttpResponse('Nice Try!')
def register(): form = RegisterForm() if form.validate_on_submit(): db.session.add(form.user) db.session.commit() login_user(form.user) flash('You are registered successfully.', 'info') return redirect(url_for('index')) return render_template('register.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): hash_password = generate_password_hash(form.password.data, method='sha256') # put data into database new_user = User(username=form.username.data, password=hash_password, email=form.email.data) datab.session.add(new_user) datab.session.commit() # redirect to login page return redirect(url_for('login')) return render_template('register.html', form=form)
def loginn(): ''' Login endpoint ''' form_login = LoginForm() form_register = RegisterForm() if request.method == 'POST': if form_login.validate_on_submit(): new = User.query.filter_by( username=form_login.username.data).first() if new is not None: if check_password_hash(new.password, form_login.password.data): login_user(new, remember=form_login.remember.data) return redirect(url_for('index')) else: flash('Username or password is incorect') else: flash('Username or password is incorect') else: if current_user.is_authenticated: return redirect(url_for('index')) return render_template('login.html', form_login=form_login, form_register=form_register)
def register_post(request): #Set request_message to blank register_message = "" success_message = "" #Once we determine the request type, set the variables if request.method == 'POST': register = RegisterForm(request.POST) username = request.POST.get('username') password = request.POST.get('password') #check post data if register.is_valid(): #define variables to send to api url = REGISTER_URL the_data = {'username': username, 'password': password} #send data r = requests.post(url, data=the_data) #load data into dictionary the_data = json.loads(r.text) if 'success' in the_data: if the_data['success'] == 'True': success_message = 'congrats, you have been signed up!' elif the_data['success'] == 'False': register_message = the_data['message'] else: register_message = "There was an unknown error" else: register_message = "There was an unknown error" else: register = RegisterForm() return render(request, 'register.html', { 'register': register, 'register_message': register_message, 'success_message': success_message, })
def register(): form = RegisterForm(request.form) if request.method == 'POST' and form.validate(): user = User.query.filter_by(email=form.email.data).first() if user is None: user = User(username=form.username.data, email=form.email.data, password=sha256_crypt.encrypt(str(form.password.data)), registeredAt=datetime.now(), confirmed=False) db.session.add(user) db.session.commit() user_settings = Setting(ageGap=2, searchDistance=30, settingsEdited=False) db.session.add(user_settings) db.session.commit() user_profile = Profile(fullname=form.name.data, firstName=form.name.data.split()[0], surname=' '.join( form.name.data.split()[1:]), username=form.username.data, profileEdited=False) db.session.add(user_profile) db.session.commit() token = s.dumps(form.email.data) msg = Message('Confirm your Email! :)', recipients=[form.email.data]) link = url_for('confirmed', token=token, _external=True) msg.body = f"Your confirmation link is: {link}" mail.send(msg) return redirect(url_for('confirm_email')) else: flash("Email or Username already being used!") return render_template('register.html', form=form)
def login(): ''' Login view Workaround to have 2 forms on the same page ''' if current_user.is_authenticated: return redirect(url_for('index')) form_register = RegisterForm() form_login = LoginForm() return render_template('login.html', form_login=form_login, form_register=form_register)
def register(request): if request.method == 'POST': form = RegisterForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass username = form.cleaned_data['username'] password = form.cleaned_data['password'] secpassword = form.cleaned_data['secpassword'] email = form.cleaned_data['email'] if password == secpassword: try: user = User.objects.create_user(username, email, password) except IntegrityError: t = loader.get_template('main/register.html') message = "Error: The Username is already taken" context = util.generateContext(request, contextType = 'RequestContext', form=form, message=message) return HttpResponseServerError(t.render(context)) #user.profile = UserProfile(user=user) user.profile.save() profile = user.get_profile() profile.url = username print profile.url print username profile.save() user = authenticate(username=username, password=password) login(request, user) return redirect('/') else: message = "Error: The Passwords didn't match" else: message = "There was a problem with the entered values" t = loader.get_template('main/register.html') context = util.generateContext(request, contextType = 'RequestContext', form=form, message=message) return HttpResponseServerError(t.render(context)) else: form = RegisterForm() context = util.generateContext(request, contextType = 'RequestContext', form=form) return render_to_response('main/register.html', context)
def register_handle(): form=RegisterForm(request.form) if request.method=="POST" and form.validate(): stat = check_user(request.form['username']) if stat==True: flash("This username already taken") return redirect(url_for("register_handle")) else: username=request.form['username'] email =request.form['email'] password= request.form['pswd'] first_name =request.form['firstname'] last_name = request.form['lastname'] print("dfghjkl") print("fffff",username, password, email, first_name, last_name) add_user(password,username,email,first_name,last_name) flash("welcome"+username) session['logged_in'] = True session['username'] = username return redirect(url_for("dashboard")) return render_template("register.html", form=form)
def register_data(request): frm = RegisterForm() ctx = {'form': frm} return render(request, 'signinpage.html', ctx)