def post(self): username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') if not utils.valid_username(username) or not utils.valid_password(password) or (not utils.valid_email(email) and "" != email) or password != verify: errorUsername = "" errorPassword = "" errorVerify = "" errorEmail = "" if not utils.valid_username(username): errorUsername = "******" if not utils.valid_password(password): errorPassword = "******" if not utils.valid_email(email) and "" != email: errorEmail = "That's not a valid email." if password != verify: errorVerify = "Your passwords didn't match." self.render('signup.html',errorUsername=errorUsername,errorPassword=errorPassword,errorVerify=errorVerify,errorEmail=errorEmail, username=username, email=email) else: if not model.User.by_name(username): user = model.User.save_user(username,password) self.set_secure_cookie('user_id',str(user.key().id())) self.redirect('/') else: errorUsername = '******' self.render('signup.html',errorUsername=errorUsername)
def post(self): username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') if not utils.valid_username(username) or not utils.valid_password( password) or (not utils.valid_email(email) and "" != email) or password != verify: errorUsername = "" errorPassword = "" errorVerify = "" errorEmail = "" if not utils.valid_username(username): errorUsername = "******" if not utils.valid_password(password): errorPassword = "******" if not utils.valid_email(email) and "" != email: errorEmail = "That's not a valid email." if password != verify: errorVerify = "Your passwords didn't match." self.render('signup.html', errorUsername=errorUsername, errorPassword=errorPassword, errorVerify=errorVerify, errorEmail=errorEmail, username=username, email=email) else: if not model.User.by_name(username): user = model.User.save_user(username, password) self.set_secure_cookie('user_id', str(user.key().id())) self.redirect('/') else: errorUsername = '******' self.render('signup.html', errorUsername=errorUsername)
def validateFields(self): validation = {'valid': True} email = self.request.get('fields.email') password = self.request.get('fields.password') fields = {'email' : email} errors = {} validation['fields'] = fields if not utils.valid_email(email): errors['error_email'] = "That's not a valid email." validation['valid'] = False validation['errors'] = errors return validation if not utils.valid_password(password): errors['error_password'] = "******" validation['valid'] = False validation['errors'] = errors return validation userQuery = self.validateUser(fields,password) if not userQuery['userFound']: errors['error_db'] = "Invalid email/password" validation['valid'] = False validation['errors'] = errors return validation validation['errors'] = errors validation['fields']['userId'] = userQuery['userId'] return validation
def post(self): """ Redirect to welcome page if form is valid else shows form with error details """ have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username=self.username, email=self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('register.html', **params) else: self.done()
def post(self): """ Redirect to welcome page if form is valid else shows form with error details """ have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username=self.username, email=self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('signup-form.html', **params) else: self.done()
def post(self): have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username = self.username, email = self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('signup-form.html', **params) else: self.done()
def register(): global back db = get_db() current_date = get_datetime() have_error = False username = request.form['username'] password = request.form['password'] verify = request.form['verify'] user = query_db("SELECT * FROM users WHERE username = ?", [username], one=True) params = dict(username=username) if user: params['error_username'] = "******" have_error = True if not valid_username(username): params['error_username'] = "******" have_error = True if not valid_password(password): params['error_password'] = "******" have_error = True elif password != verify: params['error_verify'] = "Your passwords didn't match." have_error = True if have_error: return render_template('signup.html', **params) else: hpw = bcrypt.generate_password_hash(password) db.execute('INSERT INTO users (username, hpw, my_date) VALUES (?, ?, ?)', [username, hpw, current_date]) db.commit() session['username'] = username return redirect(back)
def post(self): logging.info(self.request.path) have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username=self.username, email=self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_password'] = "******" have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('signup-form.html', **params) else: self.done()
def post(self): #next_url = str(self.request.get('next_url')) #if not next_url or next_url.startswith('/login'): #next_url = '/' username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') valid_user = utils.valid_username(username) valid_pass = utils.valid_password(password) passwords_match = utils.verify_password(password, verify) email_valid = utils.valid_email(email) params = dict(valid_user = valid_user, valid_pass = valid_pass, passwords_match = passwords_match, email_valid = email_valid) errors = set_errors(params) if not errors: user_exists = db.GqlQuery("SELECT * FROM User WHERE name = :1", username).get() if not user_exists: new_user = User(name = username, password = utils.make_pw_hash(username, password), email = email) new_user.put() self.login(new_user) self.redirect('/wiki') # CHANGE THIS!!! else: error_user = "******" self.render("signup.html", error_user = error_user) else: self.render("signup.html", username=username, email=email, **errors)
def post(self): input_username = self.request.get("username") input_password = self.request.get("password") input_verify = self.request.get("verify") input_email = self.request.get("email") valid_username = u4.valid_username(input_username) valid_password = u4.valid_password(input_password) valid_verify = u4.valid_verify(input_password, input_verify) valid_email = u4.valid_email(input_email) errors = ["", "", "", ""] if not valid_username: errors[0] = "That's not a valid username." if not valid_password: errors[1] = "That wasn't a valid password." if not valid_verify: errors[2] = "Your passwords didn't match." if not valid_email and input_email != "": errors[3] = "That's not a valid email." if errors != ["", "", "", ""]: self.write_form(errors, input_username, "", "", input_email) else: user_existence = User.all().filter('username =', input_username).get() if user_existence: errors[0] = "That user already exists." self.write_form(errors, input_username, "", "", input_email) else: hashed_pw = u4.make_pw_hash(str(input_username), str(input_password)) u= User(username=str(input_username), hashed_pw=hashed_pw, email=str(input_email)) u.put() self.login(username=str(input_username), secret=secret) self.redirect("/welcome")
def register_user_route(): resp = {'success': True, 'msg': 'Registration Successful'} try: json_ = { k: v for k, v in request.get_json(force=True).items() if k and v } for k in ['username', 'password', 'firstName', 'lastName']: if k not in json_.keys(): raise Exception("Missing parameter '" + k + "'") elif type(json_[k]) != str: raise Exception('Parameter ' + k + ' is of wrong type') if username_taken(json_['username']): raise Exception( 'Provided username is already taken. Please try another one.') valid = valid_password(json_['password']) if not valid['valid']: raise Exception(valid['reason']) register = register_user(**json_) if not register: raise Exception('Registration failed. Try again later.') set_session_user(json_['username']) except Exception as e: print(e) resp['success'] = False resp['msg'] = e.args[0] return jsonify(resp)
def post(self, name): username = self.request.get("username") password = self.request.get("password") vpass = self.request.get("vpass") email = self.request.get("email") have_error = False; words={"username": username, "email":email} if not utils.valid_username(username): words["error_msg_user"] = "******" have_error = True if not utils.valid_password(password): words["error_msg_pass"] = "******" have_error = True if password!=vpass: words["error_msg_vpass"] = "******" have_error = True if not utils.valid_email(email): words["error_msg_email"] = "That is not a valid email address" have_error=True if have_error: self.render("signup.html", **words) else: # check if users already exist if Users.by_name(username): words["error_msg_user"] = "******" self.render("signup.html", **words) else: u = Users.create(username, password, email) u.put() self.set_secure_cookie('User-id', str(u.key().id())) self.redirect(name)
def post(self): have_error = False next_url = str(self.request.get('next_url')) if not next_url or next_url.startswith('/login'): next_url = '/' self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username = self.username, email = self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('wiki_signup.html', **params) else: self.done()
def post(self): username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') user = User.by_name(username) values = {} if not u.valid_username(username): values['error_username'] = "******" if user: values['error_username2'] = "Username already exists." if not u.valid_password(password): values['error_password'] = "******" if password != verify: values['error_verify'] = "Your passwords didn't match." if not u.valid_email(email): values['error_email'] = "That's not a valid email." if values: values.update({'username' : username, 'email' : email}) self.markup('signup.html', **values) else: password_hashed = u.make_password_hash(username, password) user = User(username = username, password_hashed = password_hashed, email = email) user.put() self.set_cookie("user_id", str(user.key().id())) self.redirect("/dashboard")
def post(self): have_error = False if not self.valid_form(): have_error = True self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username = self.username, email = self.email) if not utils.valid_username(self.username): params['error_username'] = u"Neplatné uživatelské jméno." have_error = True if not utils.valid_password(self.password): params['error_password'] = u"Neplatné uživatelské heslo." have_error = True elif self.password != self.verify: params['error_verify'] = u"Hesla se neshodují." have_error = True if not utils.valid_email(self.email): params['error_email'] = u"Toto není platná emailová adresa." have_error = True if have_error: self.render('signup-form.html', **params) else: self.done()
def post(self): name = self.request.get('name') email = self.request.get('email') password = self.request.get('password') verify_password = self.request.get('verify_password') key = self.request.get('key') error = False error_name = "" error_password = "" error_email = "" error_verify = "" if not utils.valid_username(name): error_name="Your username needs to be between 3 and 20 characters long and only contain numbers and letters" error = True if not utils.valid_password(password): error_password="******" error = True if not utils.valid_email(email): error_email="Please type in a valid email address" error = True if password != verify_password: error_verify="Please ensure your passwords match" error = True if key != "Nicholas001": error_key="Please provide the correct key" error = True if not error: pw_hash = utils.make_pw_hash(name, password) user = model.User(parent=model.users_key(), name=name, email=email, pw_hash=pw_hash) user.put() self.login(user) self.redirect('/fileupload') else: js_code = "$('#register').modal('show');" data = { 'error_name':error_name, 'error_password':error_password, 'error_email':error_email, 'error_verify':error_verify, 'error_key':error_key, 'js_code':js_code } self.render('register.html', data=data) """
def get_user(username, password): '''If user exists and return user object, otherwise return None''' query = db.GqlQuery("SELECT * FROM User " "WHERE username = '******'" % username) results = list(query) if len(results): user = results[0] if utils.valid_password(password, user.password): user.user_id = user.key().id() return user return None
def validate_form(signup, input_username, input_password, input_verify=None, input_email=None): """ params: - signup: true for signup validation, false for login validation - username and password - input_verify, input_email: optional parameters returns: - returns true if input is valid, false otherwise and - dictionary (params) of errors """ params = {} valid_input = True valid_username = utils.valid_username(input_username) if not valid_username: valid_input = False params['error_username'] = "******" valid_password = utils.valid_password(input_password) if not valid_password: valid_input = False params['error_password'] = "******" if not input_verify and signup: valid_input = False params['error_verify'] = "verify password" if input_verify and signup: valid_verify = utils.valid_password(input_verify) if input_password != input_verify: valid_input = False params['error_verify'] = "Password and Verification do not match" if input_email and signup: valid_email = utils.valid_email(input_email) if not valid_email: params['error_email'] = "Invalid email address" params['return_email'] = input_email return valid_input, params
def post(self): # Get user input username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') # Process results input_error = False user_error = "" passwd_error = "" verify_error = "" email_error = "" if not utils.valid_username(username): user_error = "That's not a valid username" input_error = True if not utils.valid_password(password): passwd_error = "That wasn't a valid password" input_error = True elif password != verify: verify_error = "Your passwords didn't match" input_error = True if not utils.valid_email(email): email_error = "That's not a valid email" input_error = True # Check if this user is already in our registry if not input_error and User.by_name(username): user_error = "The user already exists" input_error = True if not input_error: # Create user entry in database hashed_pw = utils.make_pw_hash(username, password) u = User(name=username, hashed_pw=hashed_pw, email=email) u.put() # Set cookie to user_id uid = u.key().id() user_id = utils.make_secure_cookie(str(uid)) self.response.headers.add_header('Set-Cookie', 'user_id=%s; Path=/' % user_id) # Redirect to welcome page self.redirect('/blog/welcome') else: self.render('signup.html', username=username, email=email, user_error=user_error, passwd_error=passwd_error, verify_error=verify_error, email_error=email_error)
def post(self): error_username = '' error_password = '' error_verify = '' error_email='' username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') if (valid_user(username) and valid_password(password) and valid_verify(verify,password)) and ((valid_email(email) or email=='')): user1 = db.GqlQuery('SELECT * FROM User WHERE username = :1', username)# see if username already exists user2 = db.GqlQuery('SELECT * FROM User WHERE email = :1', email)# see if email already exists if not (user1.get() and user2.get()): new_user = User(username = username, password = make_pw_hash(username, password), email = email) new_user.put() user_id = new_user.key().id() self.response.headers.add_header('Set-Cookie', 'user_id = %s' %user_id)#set cookie self.redirect('/welcome') else: if user1.get(): error_username = '******' if user2.get(): error_email = 'Email already exists!' self.render('signup.html',username=username, password=password, verify=verify, email=email, error_username=error_username, error_password=error_password, error_verify=error_verify, error_email=error_email) else: if not valid_user(username): error_username = "******" if not valid_password(password): error_password = "******" if not valid_verify(verify,password) or not(password and verify): error_verify = "Your passwords didn't match " if not (valid_email(email) or email == ''): error_email = "That's not a valid email!" self.render('signup.html', username=username, password=password, verify=verify, email=email, error_username=error_username, error_password=error_password, error_verify=error_verify, error_email=error_email)
def validateFields(self): validation = {'valid': True} username = self.request.get('fields.username') password = self.request.get('fields.password') verifyPass = self.request.get('fields.verifyPass') email = self.request.get('fields.email') fields = {'username':username, 'password':password, 'verifyPass':verifyPass, 'email':email} errors = {} validation['fields']=fields user = self.validateUser(fields) if user['userFound']: validation['valid'] = False errors['error_email'] = "This email is already registered" validation['errors'] = errors return validation if not utils.valid_email(email): validation['valid'] = False errors['error_email'] = "That's not a valid email." validation['errors'] = errors return validation if not utils.valid_username(username): validation['valid'] = False errors['error_username'] = "******" validation['errors'] = errors return validation if not utils.valid_password(password): validation['valid'] = False errors['error_password'] = "******" validation['errors'] = errors return validation elif verifyPass != password: validation['valid'] = False errors['error_verify'] = "Passwords do not match" validation['errors'] = errors return validation validation['errors'] = errors return validation
def post(self): user_name = self.request.get('username') user_password = self.request.get('password') user_verify = self.request.get('verify') user_email = self.request.get('email') name = utils.valid_username(user_name) password = utils.valid_password(user_password) verify = utils.valid_verify(user_verify, user_password) email = utils.valid_email(user_email) nameerror = passworderror = verifyerror = emailerror = "" if not name: nameerror = "That's not a valid username" if not password: passworderror = "That's not a valid password" if password and not verify: verifyerror = "Your passwords didn't match" if user_email and not email: emailerror = "That's not a valid email" if (not (name and password and verify)) or (user_email and not email): self.render_signup(user_name, nameerror, passworderror, verifyerror, user_email, emailerror) else: # lookup user u = User.gql("WHERE username = '******'" % user_name).get() # If user already exists if u: nameerror = "That user already exists" self.render_signup(user_name, nameerror, passworderror, verifyerror, user_email, emailerror) else: # make salted password hash h = utils.make_pw_hash(user_name, user_password) u = User(username=user_name, password=h) u.put() user_id = u.key().id() uid_cookie = str(self.put_user_id_cookie(user_id, h)) self.response.headers.add_header( "Set-Cookie", "user_id=%s; Path=/" % uid_cookie) self.redirect("/")
def post(self): valid_cookie = self.request.cookies.get("user_id") if valid_cookie: import globals if globals.users != None: has_error = False user_input = self.request.get("username") password_input = self.request.get("password") verify_input = self.request.get("verify") email_input = self.request.get("email") valid_u = utils.valid_username(user_input) valid_p = utils.valid_password(password_input) valid_e = utils.valid_email(email_input) user_error = "" pass_error = "" email_error = "" verify_error = "" if not valid_u: user_error = "Invalid username, please try again." has_error = True if not valid_p: pass_error = "Invalid password, please try again." has_error = True if password_input != verify_input: verify_error = "Passwords do not match, try again." has_error = True if not valid_e and email_input != "": email_error = "Invalid email, please try again." has_error = True if has_error != False: self.render( "signup.html", error_user=user_error, error_pass=pass_error, error_verify=verify_error, error_email=email_error, username=user_input, email=email_input, user=globals.users, ) else: self.redirect("/unit2/welcome?username="******"/")
def post(self): user_name = self.request.get('username') user_password = self.request.get('password') user_verify = self.request.get('verify') user_email = self.request.get('email') name = utils.valid_username(user_name) password = utils.valid_password(user_password) verify = utils.valid_verify(user_verify, user_password) email = utils.valid_email(user_email) nameerror = passworderror = verifyerror = emailerror = "" if not name: nameerror = "That's not a valid username" if not password: passworderror = "That's not a valid password" if password and not verify: verifyerror = "Your passwords didn't match" if user_email and not email: emailerror = "That's not a valid email" if (not (name and password and verify)) or (user_email and not email): self.render_signup(user_name, nameerror, passworderror, verifyerror, user_email, emailerror) else: # lookup user u = User.gql("WHERE username = '******'"%user_name).get() # If user already exists if u: nameerror = "That user already exists" self.render_signup(user_name, nameerror, passworderror, verifyerror, user_email, emailerror) else: # make salted password hash h = utils.make_pw_hash(user_name, user_password) u = User(username=user_name, password=h) u.put() user_id = u.key().id() uid_cookie = str(self.put_user_id_cookie(user_id, h)) self.response.headers.add_header("Set-Cookie", "user_id=%s; Path=/"%uid_cookie) self.redirect("/")
def post(self): # NOTES: this kind of technique I'm using won't scale well. Need to # transition to a system where a dict is contructed dynmically. username = self.request.get('username').lower() password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') vdata = dict(self.request.params) submit_error = False if not utils.valid_username(username): vdata['e_username'] = "******" submit_error = True if utils.valid_password(password): if password != verify: vdata['e_verify'] = "Your passwords didn't match." submit_error = True else: vdata['e_password'] = "******" submit_error = True if submit_error: self.render('signup_form.html', vdata=vdata) else: #form filled out successfully, check DB for dupes user_rec = Users.by_username(username) if user_rec: # dupe!!! vdata['e_username'] = "******" self.render('signup_form.html', vdata=vdata) else: # sign up form was successful. Now, first create a password # hash and create a Users entity. new_user = Users.register(username, password, email) new_user.put() # now we want to store a cookie indicating a user. send # the "Set-Cookie" data in the redirect response :) user_id = new_user.key().id() self.set_secure_cookie('user_id', user_id) self.redirect(URL_ROOT)
def post(self): # try: email = self.request.get('email') password = self.request.get('password') templateVals = {'signinEmail': email} if email and password: user = User.get_by_id(email) if user: if utils.valid_password(email, password, user.passwordHash): self.login(user) self.redirect("/") else: templateVals['signinError'] = "Invalid password!" else: templateVals['signinError'] = "Account doesn't exist for this Email ID!" else: templateVals['signinError'] = "Enter both Email ID and Password!" self.render('signin.html', **templateVals)
def register(): if request.method == 'GET': return render_template('register.html') username = request.form['username'] password = request.form['password'] if not (utils.valid_username(username) and utils.valid_password(password)): flash("Please use only a username of only letters and/or numbers between 3 and 20 characters") return render_template('register.html') if username_taken(username): flash("username is already taken, please try another") return render_template('register.html') else: add_user(username, password) login_session(username) return redirect(url_for('home'))
def post(self): have_error = False # get user input from request username = self.request.get('username') password = self.request.get('password') verify_password = self.request.get('verify_password') email = self.request.get('email') verify_email = self.request.get('verify_email') # set params to be passed back to form if error params = dict(username = username, email = email) # get users from db user = User.by_name(username) # check if username already exists, if exists return error if user: params['exist_error'] = "That username already exists!" have_error = True # check that username is valid if not utils.valid_username(username): params['error_username'] = "******" have_error = True # check that passoword is valid and passwords match if not utils.valid_password(password): params['error_password'] = "******" have_error = True elif password != verify_password: params['error_verify_password'] = "******" have_error = True # check that email is valid and match if not utils.valid_email(email): params['error_email'] = "That's not a valid email!" have_error = True # if there is error, rerender form with error params, # else redirect to main if have_error: self.render("signup.html", **params) else: # store in User table u = User.register(username, password, email) u.put() # set secure cookie self.login(u) self.redirect('/')
def process_form(self, post_data): """ Utility function to process the form and generate errors. """ username = post_data[0] password = post_data[1] verify = post_data[2] email = post_data[3] errors = {} if not username or not valid_username(username): errors['username_error'] = "That's not a valid username." if not password or not valid_password(password): errors['password_error'] = "That wasn't a valid password." else: if not verify or verify != password: errors['verify_error'] = "Your passwords didn't match." if email and not valid_email(email): errors['email_error'] = "That's not a valid email." if errors: errors['email'] = email errors['username'] = username return errors
def post(self): username = self.request.get('username') password = self.request.get('password') err_usr = '' err_pass = '' try: user = models.User.get_by_name(username) if not user: err_usr = "******" if not utils.valid_password(username, password, user.pw_hash): err_pass = "******" if err_usr or err_pass: self.render("login.html", err_usr=err_usr, err_pass=err_pass, username=username) else: self.login(user) self.redirect("/") except AttributeError: self.redirect("/signup")
def post(self): error_input = False username = self.request.get('username') password = self.request.get('password') verify = self.request.get('verify') email = self.request.get('email') params = dict(username=username, email=email) if not valid_username(username): params['error_username'] = "******" error_input = True if not valid_password(password): params['error_password'] = "******" error_input = True elif password != verify: params['error_verify'] = "Your passwords do not match" error_input = True if not valid_email(email): params['error_email'] = "That's not a valid email" error_input = True if error_input: self.render('signup_page.html', **params) else: user = User.find_by_name(username) if user: params['error_username'] = "******" self.render('signup_page.html', **params) else: user = User.register(username, password, email) user.put() self.login(user) self.redirect('/home')
def post(self): input_username = self.request.get("username") input_password = self.request.get("password") input_verify = self.request.get("verify") input_email = self.request.get("email") valid_username = u4.valid_username(input_username) valid_password = u4.valid_password(input_password) valid_verify = u4.valid_verify(input_password, input_verify) valid_email = u4.valid_email(input_email) errors = ["", "", "", ""] if not valid_username: errors[0] = "That's not a valid username." if not valid_password: errors[1] = "That wasn't a valid password." if not valid_verify: errors[2] = "Your passwords didn't match." if not valid_email and input_email != "": errors[3] = "That's not a valid email." if errors != ["", "", "", ""]: self.write_form(errors, input_username, "", "", input_email) else: user_existence = User.all().filter('username =', input_username).get() if user_existence: errors[0] = "That user already exists." self.write_form(errors, input_username, "", "", input_email) else: hashed_pw = u4.make_pw_hash(str(input_username), str(input_password)) u = User(username=str(input_username), hashed_pw=hashed_pw, email=str(input_email)) u.put() self.login(username=str(input_username), secret=secret) self.redirect("/welcome")
def post(self): if self.user: self.session.add_flash("You are already logged in") self.redirect('/') else: self.username = self.request.get('username') self.password = self.request.get('password') self.confirm = self.request.get('confirm') self.email = self.request.get('email') params = dict(username=self.username, email=self.email) have_error = False if not valid_username(self.username): params['error_username'] = '******' have_error = True elif User.user_by_name(self.username): params['error_username'] = '******' have_error = True if not valid_password(self.password): params['error_password'] = '******' have_error = True elif self.password != self.confirm: params['error_confirm'] = 'Passwords do not match' have_error = True if not valid_email(self.email): params['error_email'] = 'Invalid email' have_error = True if have_error: self.render('registration.html', **params) else: user = User.register_user(username=self.username, password=self.password, email=self.email) user.put() self.login(user) self.session.add_flash("Welcome, %s!" % user.username) self.redirect('/')
def post(self): username = self.request.get("username") password = self.request.get("password") verify = self.request.get("verify") email = self.request.get("email") username_error = "" password_error = "" verify_error = "" email_error = "" if not utils.valid_username(username): username_error = "That's not a valid username." elif db.GqlQuery("SELECT * FROM User WHERE username = '******'" % username).count() != 0: username_error = "Username already exists." if utils.valid_password(password): if not password == verify: verify_error = "Your passwords didn't match." else: password_error = "That wasn't a valid password." if not utils.valid_email(email): email_error = "That's not a valid email." if (username_error != "" or password_error != "" or verify_error != "" or email_error != ""): self.write_form([username, username_error], password_error, verify_error, [email, email_error]) else: user = models.User(username=username, hashed_pw=utils.make_pw_hash(username, password), email=email) user.put() self.response.headers.add_header('Set-Cookie', str('user-id=%s; Path=/' % utils.make_secure_val(utils.SECRET, username))) self.redirect("/blog/welcome")
def post(self): have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username = self.username, email = self.email) if not valid_username(self.username): params['error_username'] = "******" have_error = True u = User.by_name(self.username) if u: params['error_username'] = "******" have_error = True if not valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not valid_email(self.email): params['error_email'] = "that's not a valid email" have_error = True if have_error: self.render('signup-form.html', **params) else: u = User.register(self.username, self.password, self.email) u.put() self.site_login(u) self.redirect('/blog/welcome') #?username=' + username)
def register(): global back db = get_db() current_date = get_datetime() have_error = False username = request.form['username'] password = request.form['password'] verify = request.form['verify'] user = query_db("SELECT * FROM users WHERE username = ?", [username], one=True) params = dict(username=username) if user: params['error_username'] = "******" have_error = True if not valid_username(username): params['error_username'] = "******" have_error = True if not valid_password(password): params['error_password'] = "******" have_error = True elif password != verify: params['error_verify'] = "Your passwords didn't match." have_error = True if have_error: return render_template('signup.html', **params) else: hpw = bcrypt.generate_password_hash(password) db.execute( 'INSERT INTO users (username, hpw, my_date) VALUES (?, ?, ?)', [username, hpw, current_date]) db.commit() session['username'] = username return redirect(back)
def post(self): have_error = False self.username = self.request.get("username") self.password = self.request.get("password") self.verify = self.request.get("verify") self.email = self.request.get("email") params = dict(username=self.username, email=self.email) if not utils.valid_username(self.username): have_error = True params['error_username'] = "******" if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your password didn't match" have_error = True if have_error: self.render('/signup-form.html', **params) else: self.done()
def post(self): have_error = False self.username = self.request.get('username') self.password = self.request.get('password') self.verify = self.request.get('verify') self.email = self.request.get('email') params = dict(username=self.username, email=self.email) if not utils.valid_username(self.username): params['error_username'] = "******" have_error = True if not utils.valid_password(self.password): params['error_password'] = "******" have_error = True elif self.password != self.verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not utils.valid_email(self.email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('register.html', **params) else: self.done()
def validate(cls, name, password): u = cls.by_name(name) if u and utils.valid_password(name, password, u.password_hash): return u
def post(self): if not self.user: self.redirect("/signup") upd_pro = self.request.get("upd_pro") upd_pwd = self.request.get("upd_pwd") if upd_pro == "1": self.email = self.request.get("email") if self.request.get("email") else self.user.email self.bio = self.request.get("bio") if self.request.get("bio") else self.user.bio have_error = False params = { "email": self.email, "bio": self.bio } if not utils.valid_email(self.email): params["error"] = "That's not a email." have_error = True if have_error: self.render("update_profile.html", **params) else: u = self.user u.email = self.email u.bio = self.bio u.put() self.redirect("/profile") if upd_pwd == "1": self.password = self.request.get("password") self.new_pwd = self.request.get("new_pwd") self.verify = self.request.get("verify") have_error = False params = {"password": self.password, "new_pwd": self.new_pwd, "verify": self.verify } if not utils.valid_password(self.new_pwd): params["error"] = "That's not a valid password." have_error = True elif self.new_pwd != self.verify: params["error"] = "Your passwords don't match." have_error = True elif not entities.User.User.login(self.user.name, self.password): # Note that User.login takes a username and pw, and returns the user object if the pw is correct params["error"] = "That's not your current password." have_error = True if have_error: self.render("change_password.html", **params) else: u = self.user new_pw_hash = entities.User.make_pw_hash(self.user.name, self.new_pwd) print new_pw_hash u.pw_hash = new_pw_hash u.put() self.redirect("/profile")
def post(self): globals.init() current_url = self.request.url.split('/')[-1] if current_url == 'main': globals.main_page = True has_error = False user_input = self.request.get('username') password_input = self.request.get('password') verify_input = self.request.get('verify') email_input = self.request.get('email') valid_u = utils.valid_username(user_input) valid_p = utils.valid_password(password_input) valid_e = utils.valid_email(email_input) user_error = '' pass_error = '' email_error = '' verify_error = '' if not valid_u: user_error = 'Invalid username, please try again.' has_error = True if not valid_p: pass_error = 'Invalid password, please try again.' has_error = True if password_input != verify_input: verify_error = 'Passwords do not match, try again.' has_error = True if not valid_e and email_input != '': email_error = 'Invalid email, please try again.' has_error = True if has_error != False: if not globals.main_page: self.render("register.html",error_user = user_error ,error_pass = pass_error,error_verify = verify_error,error_email = email_error,username = user_input,email = email_input) else: self.render("register_main.html",error_user = user_error ,error_pass = pass_error,error_verify = verify_error,error_email = email_error,username = user_input,email = email_input) else: hash_pass = utils.make_pw_hash(user_input,password_input) user_input = str(user_input) user_taken = False email_taken = False data = db.GqlQuery("select * from Users order by user_name") for entry in data: user = entry.user_name email= entry.user_email if user == user_input: user_taken = True if email == email_input and email != '': email_taken = True if user_taken or email_taken: user_error = 'Sorry, the username you selected is already taken' email_error= 'Sorry, this email is already registered' if user_taken and email_taken: if not globals.main_page: self.render('register.html', error_user = user_error, error_email = email_error) else: self.render('register_main.html', error_user = user_error, error_email = email_error) if user_taken: if not globals.main_page: self.render('register.html', error_user = user_error, email = email_input) else: self.render('register_main.html', error_user = user_error, email = email_input) else: if not globals.main_page: self.render('register.html', error_email = email_error, username = user_input) else: self.render('register_main.html', error_email = email_error, username = user_input) else: new = Users(user_name = user_input, user_pass = hash_pass, user_email = email_input) new.put() self.response.headers.add_header('Set-Cookie', 'user_id=%s|%s; Path=/' % (new.key().id(),hash_pass)) if globals.main_page: self.redirect('/homework') else: self.redirect('/wiki/')