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 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): #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 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): 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): 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): 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): 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): 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, 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 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 get(self): validate_username_cookie = self.read_secure_cookie('username') try: username = validate_username_cookie.split("|")[0] if u4.valid_username(username): self.render('wiki_welcome.html', {"username":username}) except: self.redirect("/signup")
def get(self): validate_username_cookie = self.read_secure_cookie('username') try: username = validate_username_cookie.split("|")[0] if u4.valid_username(username): self.render('wiki_welcome.html', {"username": username}) except: self.redirect("/signup")
def get(self): """ Welcome a valid user or redirect to signup page """ username = self.request.get('username') if utils.valid_username(username): self.render('welcome.html', username=username) else: self.redirect('/mock/signup/')
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 post(self): self.username = self.request.get('username') self.password = self.request.get('password') self.v_password = self.request.get('verify') self.email = self.request.get('email') usererror = '' passerror = '' vpasserror = '' emailerror = '' if self.username: u_present = True if not valid_username(self.username): usererror = "That's not a valid username." else: usererror = "That's not a valid username." if self.password: p_present = True if not valid_pass(self.password): passerror = "That wasn't a valid password." else: passerror = "That wasn't a valid password." if self.v_password: vp_present = True if not valid_pass(self.v_password): vpasserror = "That wasn't a valid verification password." else: vpasserror = "That wasn't a valid verification password." if self.email: email_present = True if not valid_email(self.email): emailerror = "That wasn't a valid email." if self.password != self.v_password: passerror = "Passwords do not match" if usererror == '' and passerror == '' \ and vpasserror == '' and emailerror == '': self.done() else: self.render("signup.html", username=self.username, usererror=usererror, passerror=passerror, vpasserror=vpasserror, emailerror=emailerror) def done(self, *a, **kw): raise NotImplementedError
def get_user_name(): user = "" user_in = False while user_in is False: print "Please enter your name (between 3 and 20 characters long):" user = raw_input() if valid_username(user): user_in = True else: print "Invalid username! Do you want to die a nameless hero???" s() return user
def get(self): username = self.request.get("username") valid_cookie = self.request.cookies.get("user_id") if valid_cookie: import globals if globals.users != None: if utils.valid_username(username): self.render("welcome.html", username=username, user=globals.users) else: self.redirect("/unit2/signup") else: self.redirect("/")
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 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 run_test(): """ Tests for verifying functions """ # create a TestSuite object suite = poc_simpletest.TestSuite() ##run tests #test fermat sre = utils.valid_username('stijn') suite.run_test('stijn' and sre, sre, 'test') # report number of tests and failures suite.report_results()
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): 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 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 signIn(self, request): """ This function register a new user as player. Input: A unique username and email address""" username = request.username email = request.email if not utils.valid_username(username) or not utils.valid_email(email): raise endpoints.ConflictException('Invalid Input') if Player.query(Player.username == request.username).get(): raise endpoints.ConflictException( 'A User with that name already exists!') Player(username=username, email=email).put() # create default player if not exist if not Player.query(Player.username == "computer").get(): self._defaultPlayer() return MessageForm(message="Welcome Player %s. Enjoy racing!!!" % username)
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 wiki_base_links(self, pagename, currentlyediting=False): validate_username_cookie = self.read_secure_cookie('username') try: username = validate_username_cookie.split("|")[0] except: username = None link1_url = "" link1_label = "" link2_url = "" link2_label = "" link3_url = "" link3_label = "" currentusername = "" #currentusername is for template rendering purposes only if username == None: link1_url = "/login" link1_label = "login" link2_url = "/signup" link2_label = "signup" elif u4.valid_username(username): if currentlyediting == True: link1_url = "/logout" link1_label = "logout" link2_url = "/_history" + pagename link2_label = "page history" currentusername = "******" % ( str(username)) elif currentlyediting == False: link1_url = "/_edit" + pagename link1_label = "edit" link2_url = "/_history" + pagename link2_label = "history" link3_url = "/logout" link3_label = "logout" currentusername = "******" % ( str(username)) return link1_url, link1_label, link2_url, link2_label, link3_url, link3_label, currentusername, username
def signup(): ref = request if request.method == 'POST': try: username = request.form.get('user_username') email = request.form.get('user_email') password = utils.hash_password(request.form.get('user_password')) firstname = request.form.get('user_firstname') lastname = request.form.get('user_lastname') repeat_password = utils.hash_password(request.form.get('user_repeat_password')) if password != repeat_password: error = " Passwords do not match ! " return render_template('signup.html', error=error) if not utils.valid_username(username): traceback.print_exc() error = " Username is already taken " return render_template('signup.html', error=error) if not utils.valid_email(email): traceback.print_exc() p = re.compile('[aA0-zZ9$]+@[aA0-zZ9]+.[a-z]+') if p.match(email) is None: error = " Email is already taken " else: error = " Invalid Email" return render_template('signup.html', error=error) session['username'] = username # session['password'] = password query = ExploriumDbApi.USERS_TABLE.insert().values(username=username, password=password, email=email, firstname=firstname, lastname=lastname) ExploriumDbApi.conn.execute(query) return render_template('index.html', this_username=session['username'], show_what="Welcome!", result_info_list='') except Exception as e: render_template('signup.html', error='Invalid Input') return render_template('signup.html')
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 wiki_base_links(self, pagename, currentlyediting=False): validate_username_cookie = self.read_secure_cookie('username') try: username = validate_username_cookie.split("|")[0] except: username = None link1_url = "" link1_label = "" link2_url = "" link2_label = "" link3_url = "" link3_label = "" currentusername = "" #currentusername is for template rendering purposes only if username == None: link1_url = "/login" link1_label = "login" link2_url = "/signup" link2_label = "signup" elif u4.valid_username(username): if currentlyediting == True: link1_url = "/logout" link1_label = "logout" link2_url = "/_history" + pagename link2_label = "page history" currentusername = "******" % (str(username)) elif currentlyediting == False: link1_url = "/_edit" + pagename link1_label = "edit" link2_url = "/_history" + pagename link2_label = "history" link3_url = "/logout" link3_label = "logout" currentusername = "******" % (str(username)) return link1_url, link1_label, link2_url, link2_label, link3_url, link3_label, currentusername, username
def post(self): username = self.request.get("username") password = self.request.get("password") error = False if not utils.valid_username(username): error = True else: user_data = db.GqlQuery("SELECT * FROM User WHERE username = '******'" % username).get() if not user_data: error = True elif not utils.valid_pw(username, password, user_data.hashed_pw): error = True if (error): self.render("Week4/login.html", username=username, error="Invalid login") else: 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): 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): 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): 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 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") 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): 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): 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 test_valid_username_valid(self): username = '******' is_valid = utils.valid_username(username) self.assertTrue(is_valid)
def edit_profile(): if 'username' not in session or 'password' not in session: return redirect(url_for('signin')) if session['username'] == 'guest': return redirect(url_for('index')) if request.method == 'GET': if 'username' not in session: return redirect(url_for('signin')) userinfo = ExploriumDbApi.load_user_info(session['username']) error = "" return render_template('profile-edit.html', this_username=session['username'], user_info=userinfo, error=error) if request.method == "POST": try: if 'username' not in session: return redirect(url_for('signin')) firstname = request.form.get('user-firstname') lastname = request.form.get('user-lastname') email = request.form.get('user-email') username = request.form.get('user-username') userinfo = ExploriumDbApi.load_user_info(session['username']) if not firstname or not lastname or not email or not username: traceback.print_exc() error = " Fields cannot be empty. " return render_template('profile-edit.html', this_username=session['username'], user_info=userinfo, error=error) if not utils.valid_username(username) and username != userinfo['username']: error = " Username is already taken " return render_template('profile-edit.html', this_username=session['username'], user_info=userinfo, error=error) if not utils.valid_email(email) and email != userinfo['email']: p = re.compile('[aA0-zZ9$]+@[aA0-zZ9]+.[a-z]+') if p.match(email) is None: error = " Email is already taken " else: error = " Invalid Email" return render_template('profile-edit.html', this_username=session['username'], user_info=userinfo, error=error) session['username'] = username if request.form.get('user-password'): password = utils.hash_password(request.form.get('user-password')) query = ExploriumDbApi.USERS_TABLE.update().where( ExploriumDbApi.USERS_TABLE.c.user_id == userinfo['user_id']).values(firstname=firstname, lastname=lastname, username=username, email=email, password=password) else: query = ExploriumDbApi.USERS_TABLE.update().where( ExploriumDbApi.USERS_TABLE.c.user_id == userinfo['user_id']).values(firstname=firstname, lastname=lastname, username=username, email=email) ExploriumDbApi.conn.execute(query) userinfo = ExploriumDbApi.load_user_info(session['username']) return render_template('profile.html', this_username=session['username'], user_info=userinfo) except: userinfo = ExploriumDbApi.load_user_info(session['username']) error = "Invalid Input" return render_template('profile-edit.html', this_username=session['username'], user_info=userinfo, error=error)
def test_valid_username_guest(self): username = '******' is_valid = utils.valid_username(username) self.assertFalse(is_valid)
def test_valid_username_invalid(self): username = '******' is_valid = utils.valid_username(username) self.assertFalse(is_valid)
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/')