def register(request): if request.method == 'POST': form = forms1.registerForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] firstName = form.cleaned_data['firstName'] lastName = form.cleaned_data['lastName'] password = form.cleaned_data['password'] phone = form.cleaned_data['phone'] email = form.cleaned_data['email'] addr = form.cleaned_data['addr'] payment = form.cleaned_data['payment'] deliverer_non_deliverer = form.cleaned_data['deliverer_non_deliverer'] # Check if username is taken if findUser(username): form = forms1.registerForm(request.POST) return render(request, 'home/register.html', {'form' : form, 'message' : 'usernamenotavailable'}) user = models.User() user.create_user(username, firstName, lastName, password, 0, phone, email, addr, payment, 1, deliverer_non_deliverer) user.save() return HttpResponseRedirect('/login/') # Redirect after POST else: form = forms1.registerForm() # An unbound form return render(request, 'home/register.html', {'form' : form})
def register(): registerForm = forms.registerForm() return render_template('register.html', registerForm=registerForm, registerURL=url_for('verifyregister'))
def register(): form = registerForm() if g.user: return redirect(url_for("profile")) if form.validate_on_submit(): user = User( email = form.email.data, firstName = form.firstName.data, lastName = form.lastName.data, # password = form.password.data, birthday = datetime.strptime(form.birthday_month.data + '%02d'%form.birthday_day.data + form.birthday_year.data, "%b%d%Y").date(), username = form.username.data ) #logging.warning(str(user)) user.put() sendConfirmEmail(user) session["username"] = user.username if not os.environ['SERVER_SOFTWARE'].startswith('Development'): #if production, cuz mail doesn't work on dev. flash("A confirmation link has been sent to your email address.") return redirect(url_for("home")) else: token = URLSafeTimedSerializer(app.config['SECRET_KEY']).dumps(user.key.urlsafe(), salt=app.config['SECURITY_PASSWORD_SALT']) confirm_url = url_for("confirmEmail", token = token, _external = True) return "<a href={0}>Confirm</a>".format(confirm_url) #let developer do it manually return render_template("register.html", form = form)
def register(): form = registerForm() if g.user: return redirect(url_for("profile")) if form.validate_on_submit(): user = User( email=form.email.data, firstName=form.firstName.data, lastName=form.lastName.data, # password = form.password.data, birthday=datetime.strptime( form.birthday_month.data + '%02d' % form.birthday_day.data + form.birthday_year.data, "%b%d%Y").date(), username=form.username.data) #logging.warning(str(user)) user.put() sendConfirmEmail(user) session["username"] = user.username if not os.environ['SERVER_SOFTWARE'].startswith( 'Development'): #if production, cuz mail doesn't work on dev. flash("A confirmation link has been sent to your email address.") return redirect(url_for("home")) else: token = URLSafeTimedSerializer(app.config['SECRET_KEY']).dumps( user.key.urlsafe(), salt=app.config['SECURITY_PASSWORD_SALT']) confirm_url = url_for("confirmEmail", token=token, _external=True) return "<a href={0}>Confirm</a>".format( confirm_url) #let developer do it manually return render_template("register.html", form=form)
def registerUser(): RF = f.registerForm() if RF.validate_on_submit(): # add the user to DB db.cur.execute( 'INSERT INTO users (email_addr, own_password, username, real_name) VALUES (%s, %s, %s, %s);', (RF.email.data, RF.password.data, RF.username.data, RF.name.data)) db.conn.commit() accountID = db.cur.lastrowid #add the verification code to DB verificationCode = randint(1000, 9999) db.cur.execute( 'INSERT INTO verification_codes (codeNumber, accountID) VALUES (%s, %s);', (verificationCode, accountID)) db.conn.commit() # log in unverified user newUser = User('ID', accountID, True) login_user(newUser, remember=True) # send the verification message verifyMsg.recipients = [RF.email.data] verifyMsg.body = 'Hi ' + RF.name.data + ', use the code ' + str( verificationCode ) + ' to verify your email address and get your account with Joe up and running.\nIf you don\'t know about the amazing Joe project, then just ignore this email. Thanks!' with app.app_context(): mail.send(verifyMsg) return redirect('/verify/' + str(accountID)) return render_template('register.html', form=RF)
def test_invalidPhone(self): form_data = {'username': '******', 'password' : 'socute', 'firstName' : 'isaidpuppy', 'lastName' : 'hi', 'phone' : '43233fds', 'email' : '*****@*****.**', 'addr' : '4', 'payment' : 'credit', 'deliverer_non_deliverer' : '1'} form = registerForm(data=form_data) self.assertEqual(form.is_valid(), False)
def register(): # Use registerForm() to validate user input form = registerForm() # If form is valid if form.validate_on_submit(): # If user already exists if Users.query.filter_by(username=form.username.data).first(): # Flash message flash("User already exists.") # Otherwise else: # Hash input password using werkzeug security module hashed_pass = generate_password_hash(form.password.data) # Assign new variable with username and password input user = Users(username=form.username.data, password=hashed_pass) # Add user to database db.session.add(user) # Commit changes db.session.commit() # Flash message flash("Success. Please login.", "alert alert-success") # Redirect user to login page return redirect(vs_url_for('login')) return render_template('register.html', form=form)
def registerView(): if not 'token' in session: # universal variables form = registerForm() kwargs = {'formWidth': 400} if form.validate_on_submit(): dataDict = { 'regNo': form.regNo.data, 'companyName': form.companyName.data, 'userName': form.userName.data, 'email': form.email.data, 'password': form.password.data } req = authAPI('register', method='post', dataDict=dataDict) if 'error' in req: if req['error'] == 'Could not identify Platform': errorMessage(req['error']) elif req['error'] == 'Request data incomplete': errorMessage(req['error']) elif req['error'] == 'Reg/VAT number already exist': errorMessage( 'An account using this Reg/VAT number already exist') elif req['error'] == 'Invalid email-address': errorMessage(req['error']) elif req[ 'error'] == 'Illegal null values present in request data': errorMessage(req['error']) elif req['error'] == 'Internal server error': errorMessage(req['error']) elif 'success' in req: # send email confirmation subject = u'Please confirm your account' tok = req['token'] email = req['email'] confirm_url = url_for('authBP.confirmEmailView', token=tok, _external=True) html = render_template('email/verify.html', confirm_url=confirm_url) sendMail(subject=subject, sender='Henrik Poulsen', recipients=[email], html_body=html, text_body=None) successMessage( 'You have successfully registered your account, please check your email for confirmation.' ) return redirect(url_for('indexView')) return render_template('auth/registerForm.html', form=form, **kwargs) else: errorMessage('alreadyRegistered') return redirect(url_for('indexView'))
def register(self): reg_form = registerForm(request.form) login_form = loginForm(request.form) if request.method == "POST": if reg_form.submit1.data and reg_form.validate(): user = { "_id": uuid.uuid4().hex, "name": reg_form.name.data, "email": reg_form.email.data, "username": reg_form.username.data, "password": reg_form.password.data } user['password'] = sha256_crypt.encrypt(user['password']) if config.db.users.find_one({"email": user['email']}): error = "Email already exists!" return render_template(config.template, error=error, reg_form=reg_form, login_form=login_form) if config.db.users.insert_one(user): self.start_session(user) flash('You are now registered and can log in!', 'success') return render_template(config.template, reg_form=reg_form, login_form=login_form) elif login_form.submit2.data and login_form.validate(): user = config.db.users.find_one( {"username": login_form.username.data}) if user: if sha256_crypt.verify(login_form.password.data, user['password']): self.start_session(user) return render_template('dashboard.html') else: error = 'Incorrect login details!' return render_template(config.template, error=error, reg_form=reg_form, login_form=login_form) else: error = 'Username not found!' return render_template(config.template, error=error, reg_form=reg_form, login_form=login_form) error = 'Check the registered details!' return render_template(config.template, error=error, reg_form=reg_form, login_form=login_form) else: try: return render_template(config.template, reg_form=reg_form, login_form=login_form) except Exception: return "Given template does not exists."
def verifyregisterAdmin(): registerForm = forms.registerForm() if registerForm.validate_on_submit(): db = get_db() #check that the passwords match (and possibly other checks) #TODO all possible server side checks if (registerForm.passwordReg.data != registerForm.passwordConf.data): flash("Error, passwords do not match", 'danger') return redirect('/register') #check that username does not already exist elif (db.users.find({ '_id': registerForm.userNameReg.data }).count() != 0): flash("Error, user already exists", 'danger') return redirect('/register') else: #access level idea: 4 = unverified, 3 = limited, 2 = standard, 1 = administrator, 0 = banned #TODO handle a failure additionalInfo = {} #add all of the other form fields to the database for field in registerForm: #make sure not to overwrite unsecure values if field.name not in [ 'csrf_token', 'passwordReg', 'passwordConf', 'createLinuxUser', 'userNameReg' ]: additionalInfo[field.name] = field.data userSecurity = userDAO.userDAO(db) #hashing the username makes the confirm url extremely difficult to guess (and look long, as expected) user = userSecurity.add_user(registerForm.userNameReg.data, registerForm.passwordReg.data, registerForm.email.data, 2, additionalInfo) header = 'Registration Complete' body = 'The account has been added to the database successfully.' return render_template('completepage.html', header=header, body=body) else: flash("Form is missing required information, please check below", 'info') return render_template('register.html', registerForm=registerForm, registerURL=url_for('verifyregisterAdmin'))
def registerView(): form = registerForm() if 'token' in session: errorMessage('Please log out before registering a new account') return redirect(url_for('indexBP.indexView')) if form.validate_on_submit(): dataDict = {'regNo' : form.regNo.data, 'companyName' : form.companyName.data, 'userName' : form.userName.data, 'email' : form.email.data, 'password' : form.password.data} req = authAPI('register', method='post', dataDict=dataDict) if 'error' in req: errorMessage(req['error']) elif 'success' in req: data = {'uuid':req['user_uuid'], 'name':form.userName.data, 'email':form.email.data, 'phone':'', 'role':'Administrator', 'contact':True, 'initials':'', 'tenant_uuid':req['tenant_uuid'], 'groups':[]} usr = userCrud.postUser(data=data) if 'error' in usr: errorMessage(usr['error']) else: # send email confirmation subject = u'Please confirm your account' tok = req['token'] email = req['email'] confirm_url = url_for('authBP.confirmEmailView',token=tok, _external=True) html = render_template('email/verify.html', confirm_url=confirm_url) sendMail(subject=subject, sender=os.environ['mailSender'], recipients=[email], html_body=html, text_body = None) successMessage('You have successfully registered your account, please check your email for confirmation.') return redirect(url_for('indexBP.indexView')) return render_template('auth/register.html', form=form)
def register(): if current_user.is_authenticated: # if user is already logged in return redirect( vs_url_for('index') ) # do not display registration form, send to index instead form = registerForm() # instantiate registerForm class if form.validate_on_submit(): # check if the form validates user = Users(username=form.username.data) user.get_salt() user.get_hash(form.password.data) db.session.add(user) db.session.commit() flash('Registration successful. Please log in.') return redirect(vs_url_for('login')) # redirect to the login page return render_template('register.html', form=form) # display register form
def registerView(lang='dk'): if not 'token' in session: # universal variables form = registerForm() kwargs = {'formWidth':400, 'breadcrumbs': breadCrumbs('authBP.registerView')} if g.sijax.is_sijax_request: g.sijax.register_callback('validate', validateCVR) return g.sijax.process_request() if form.validate_on_submit(): dataDict = {'regNo' : form.regNo.data, 'companyName' : form.companyName.data, 'userName' : form.userName.data, 'email' : form.email.data, 'password' : form.password.data} req = authAPI('register', method='post', dataDict=dataDict) if r.status_code == 409: flashmessage('accountExists') elif r.status_code == 404: flashmessage('cvrCheckError') elif 'error' in req: if req['error'] == 'Not valid email-address': flashMessage('validateEmail') elif 'success' in req: # send email confirmation subject = u'Bekræft tilmelding' tok = req['token'] email = req['email'] confirm_url = url_for('authBP.confirmEmailView',token=tok, _external=True, lang=lang) html = render_template(lang+'/email/verify.html', confirm_url=confirm_url) # sendMail(subject=subject, sender='Henrik Poulsen', recipients=[email], html_body=html, text_body = None) flashMessage('loginSuccess') return redirect(url_for('indexView', lang=lang)) return render_template(lang+'/auth/registerForm.html', form=form, **kwargs) else: flashMessage('alreadyRegistered') return redirect(url_for('indexView', lang=lang))
def showRegisterForm(): flag = False registerForm = forms.registerForm(request.form) #select = request.form.get('comboBox') #print(str(select)) if request.method == 'POST' and registerForm.validate(): select = request.form.get('comboBox') possibleUser = User(registerForm.UserName.data, registerForm.Email.data, registerForm.Name.data, registerForm.LastName.data, registerForm.Password.data, str(select)) flag = True db.session.add(possibleUser) db.session.commit() return render_template('RH/registerpage.html', form=registerForm, flag=flag)
def register(): form = registerForm(); if form.validate_on_submit(): name = request.form.get('name') email = request.form.get('email').lower() password = request.form.get('color') user = User(email, password, name) # send email to confirm email subject = "Confirm your email for //hackRamapo" token = ts.dumps(email, salt='email-confirm-key') confirm_url = url_for( 'confirm_email', token=token, _external=True) html = render_template('email/activate.html', confirm_url=confirm_url) emails = [] emails.append(email) msg = Message(subject, sender=ADMINS[0], recipients=emails) msg.html = html try: user.save() if login_user(user, remember=False): with app.app_context(): mail.send(msg) return redirect('/profile') else: flash("unable to log in") except: print("Registration Failed") return render_template('register.html', form=form, colors=colors);
def register(): prof = registerForm() if prof.validate_on_submit(): pw = prof.passcode.data if pw != request.form['passcodeC']: flash('Passwords do NOT match.', 'error') return redirect(url_for('index')) img = prof.img.data if img: filename = secure_filename(img.filename) img.save(app.config['UPLOAD_FOLDER'] + filename) else: filename = "./static/default/default profile.jpg" fname = prof.fname.data lname = prof.lname.data uname = prof.username.data bio = prof.bio.data location = prof.location.data email = prof.email.data cdate = datetime.now().strftime("%Y-%m-%d") rows = db.session.query(UserProfile).count() profile = UserProfile(u_id=(rows + 1), username=uname, fname=fname, lname=lname, passcode=pw, email=email, loc=location, bio=bio, profImg=filename, joined=cdate) db.session.add(profile) db.session.commit() flash('Registration Successful', 'success') return jsonify(status="OK", msg="success") else: flash_errors(prof) return jsonify({"errors": form_errors(prof)})
def register(request): otherVars = {'pageType': 'register'} # if request method is post if request.method == 'POST': regForm = registerForm(request.POST) userIns = User() userIns.email = request.POST['email'] userIns.username = request.POST['email'] userIns.set_password(request.POST['password']) userIns.first_name = request.POST['first_name'] userIns.last_name = request.POST['last_name'] try: userIns.save() except: return HttpResponseRedirect(reverse('register')) userIns2 = User_Profile() userIns2.user_id = userIns.id userIns2.contact_num = request.POST['contact_num'] userIns2.save() return HttpResponseRedirect(reverse('login')) else: regForm = registerForm() # Define header groups hgrps = ( { 'name': 'Sign Up Information', 'lblwidth': '160' }, { 'name': 'Personal Information', 'lblwidth': '160' }, ) # For first header group regForm.fields["email"].widget.attrs['hgrp'] = '0' regForm.fields["email"].widget.attrs['wsize'] = '300' regForm.fields["password"].widget.attrs['hgrp'] = '0' regForm.fields["password"].widget.attrs['wsize'] = '300' regForm.fields["confirm_password"].widget.attrs['hgrp'] = '0' regForm.fields["confirm_password"].widget.attrs['wsize'] = '300' # For first header group regForm.fields["first_name"].widget.attrs['hgrp'] = '1' regForm.fields["first_name"].widget.attrs['wsize'] = '300' regForm.fields["last_name"].widget.attrs['hgrp'] = '1' regForm.fields["last_name"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].widget.attrs['hgrp'] = '1' regForm.fields["contact_num"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].label = 'Contact number' return render(request, 'main/register.html', { 'otherVars': otherVars, 'regForm': regForm, 'hgrps': hgrps, })
def register(request): otherVars = {'pageType':'register'}; # if request method is post if request.method == 'POST': regForm = registerForm(request.POST) # input validation for add user and user profile form if regForm.is_valid(): print "imhere" # save the user and user profile object into database userIns = RegisterUser() userIns.email = request.POST['email'] userIns.username = userIns.email userIns.set_password(request.POST['password']) userIns.first_name = request.POST['first_name'] userIns.last_name = request.POST['last_name'] if userIns.contact_num == None: userIns.contact_num = 'N.A' else: userIns.contact_num = request.POST['contact_num'] if userIns.company == None: userIns.company = 'N.A' else: userIns.company = request.POST['company'] userIns.is_active = True userIns.is_staff = True userIns.save() return HttpResponseRedirect(reverse('login')) else: pass else: regForm = registerForm() # Define header groups hgrps = ({'name':'Sign Up Information','lblwidth':'160'}, {'name':'Personal Information','lblwidth':'160'},) # For first header group regForm.fields["email"].widget.attrs['hgrp'] = '0' regForm.fields["email"].widget.attrs['wsize'] = '300' regForm.fields["password"].widget.attrs['hgrp'] = '0' regForm.fields["password"].widget.attrs['wsize'] = '300' regForm.fields["confirm_password"].widget.attrs['hgrp'] = '0' regForm.fields["confirm_password"].widget.attrs['wsize'] = '300' # For first header group regForm.fields["first_name"].widget.attrs['hgrp'] = '1' regForm.fields["first_name"].widget.attrs['wsize'] = '300' regForm.fields["last_name"].widget.attrs['hgrp'] = '1' regForm.fields["last_name"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].widget.attrs['hgrp'] = '1' regForm.fields["contact_num"].widget.attrs['wsize'] = '300' regForm.fields["contact_num"].label = 'Contact number' regForm.fields["company"].widget.attrs['hgrp'] = '1' regForm.fields["company"].widget.attrs['wsize'] = '300' return render(request, 'main/register.html', {'otherVars':otherVars,'regForm':regForm,'hgrps':hgrps})