def register(cls, user, pw): new_user = cls(username=user, password_hash=security.make_pw_hash(user, pw), birthday=datetime.date.today(), email="", avatar="guest-reg.jpg") new_user.put()
def create_admin(cls): new_admin = cls(username="******", password_hash=security.make_pw_hash("admin"), birthday=datetime.date.today(), email="*****@*****.**", avatar="admin-reg.jpg") new_admin.put()
def register(cls, username, password, email,phone,address): pw_hash = make_pw_hash(username, password) return Bro(parent = bro_key(), username = username, password = pw_hash, email = email, phone=phone, address=address)
def register(cls, username, password, email, phone, address): pw_hash = make_pw_hash(username, password) return Bro(parent=bro_key(), username=username, password=pw_hash, email=email, phone=phone, address=address)
def post(self): # Take in all user input username = str(self.request.get('username')) password = str(self.request.get('password')) verify = str(self.request.get('verify')) email = str(self.request.get('email')) # Validate things error = '' if not validate_username(username): error += 'Invalid username. ' if not validate_password(password, verify): error += 'Invalid password or passwords do not match. ' if not validate_email(email): error += 'Invalid email.' # All things good, then we head for making cookies otherwise, re-render page if error == '': users = db.GqlQuery("SELECT * FROM User") # Getting all users user = None # Setting default to None, because that means that we can add this user # Looping through users for var in users: if var.username == username: user = username # If there was another user with the same username if user: # Render back the page, with an error return self.render('SignupPage.html', username=username, email=email, error='Username already exists') else: # If user does not exist # Making a cookie from username and password auth_cookie_str = security.make_pw_hash(username, password) # save the username and hash to the database, as well as the email new_user = User(username=username, password=auth_cookie_str, email=email) new_user.put() # Adding cookie headers for re-direct self.response.headers.add_header('Set-Cookie', 'auth=%s;Path=/' % auth_cookie_str) self.response.headers.add_header('Set-Cookie', 'name=%s;Path=/' % username) return self.redirect('/welcome') else: return self.render('SignupPage.html', username=username, email=email, error=error, )
def update(cls,user,newusername,newpassord,newemail,newphone,newaddress): OldUsername=user.username ListUser= db.GqlQuery('Select * from Bro where username= :1',OldUsername) result=ListUser.get() setattr(result,'username',newusername) user.username=newusername setattr(result,'password',make_pw_hash(newusername,newpassord)) user.password=make_pw_hash(newusername,newpassord) setattr(result,'email',newemail) user.email=newemail setattr(result,'phone',newphone) user.phone=newphone setattr(result,'address',newaddress) user.adrdress=newaddress result.put() TaskAuthor= db.GqlQuery('Select * from Task where author= :1',OldUsername) results=TaskAuthor.run() for result in results: setattr(result,'author',newusername) result.put()
def update(cls, user, newusername, newpassord, newemail, newphone, newaddress): OldUsername = user.username ListUser = db.GqlQuery('Select * from Bro where username= :1', OldUsername) result = ListUser.get() setattr(result, 'username', newusername) user.username = newusername setattr(result, 'password', make_pw_hash(newusername, newpassord)) user.password = make_pw_hash(newusername, newpassord) setattr(result, 'email', newemail) user.email = newemail setattr(result, 'phone', newphone) user.phone = newphone setattr(result, 'address', newaddress) user.adrdress = newaddress result.put() TaskAuthor = db.GqlQuery('Select * from Task where author= :1', OldUsername) results = TaskAuthor.run() for result in results: setattr(result, 'author', newusername) result.put()
def create_family(cls): family = [[ "Mother", "XvQJFZnNnD6G9qwj", datetime.date(1960, 1, 1), "*****@*****.**", "mother-reg.jpg", "#F2E14C" ], [ "Father", "UcMRWXNsTMGj8r8E", datetime.date(1962, 3, 15), "*****@*****.**", "father-reg.jpg", "#D94B2B" ], [ "Sister", "NTHfnzZ3mKzAM9AZ", datetime.date(1985, 6, 1), "*****@*****.**", "sister-reg.jpg", "#F29441" ], [ "Brother", "PHe2UsbpCRuUbqA3", datetime.date(1991, 8, 15), "*****@*****.**", "brother-reg.jpg", "#F29441" ], [ "Cousin", "3qo74p22W9tm46PyQ", datetime.date(1988, 12, 1), "*****@*****.**", "cousin-reg.jpg", "#2DA690" ]] for entry in family: new_user = cls(username=entry[0], password_hash=security.make_pw_hash(entry[1]), birthday=entry[2], email=entry[3], avatar=entry[4], cal_color=entry[5]) new_user.put() # Put all birthdays into the calendar birthday_date = entry[2].replace(year=datetime.date.today().year) new_date = Calendar( start_date=birthday_date, title=entry[0] + " " + str(datetime.date.today().year - entry[2].year) + "th Birthday", description="Its a birthday - what else needs to be said? Party " "hard!", author=new_user, concerned_users=[entry[0]]) new_date.put()
def post(self): username_received = self.request.get('username') if (username_received != "luduvigo"): self.redirect('/') return password_received = self.request.get('password') confirmation_received = self.request.get('verify') email_received = self.request.get('email') check_user = db.GqlQuery("SELECT * FROM User WHERE username = "******"'" + username_received + "'").get() params = dict(username = username_received, email = email_received) has_error = False if check_user: params['error_username'] = "******" has_error = True else: if not utility.valid_username(username_received): params['error_username'] = "******" has_error = True if not utility.valid_password(password_received): params['error_password'] = "******" has_error = True elif password_received != confirmation_received: params['error_verify'] = "Your passwords didn't match." has_error = True if not utility.valid_email(email_received): params['error_email'] = "That's not a valid email." has_error = True if has_error: self.render('signup.html', **params) else: password = security.make_pw_hash(username_received, password_received) u = User(username = username_received, password = password, email = email_received) u.put() self.response.headers['Content-Type'] = 'text/plain' cookie_value = security.make_secure_val(str(username_received)) self.response.headers.add_header('Set-Cookie', 'name=' + cookie_value + '; Path=/') self.redirect('/welcome')
def post(self): have_error = 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 functs.valid_username(username): params['error_username'] = "******" have_error = True if not functs.valid_password(password): params['error_password'] = "******" have_error = True elif password != verify: params['error_verify'] = "Your passwords didn't match." have_error = True if not functs.valid_email(email): params['error_email'] = "That's not a valid email." have_error = True if have_error: self.render('signup-form.html', **params) else: key = db.Key.from_path('User', '{0}'.format(username)) check = db.get(key) if check != None: params['error_username'] = "******" self.render('signup-form.html', **params) else: new_user = User(key_name= username, password= (security.make_pw_hash(username, password)), email= email) new_user.put() self.response.headers.add_header('Set-Cookie', 'username={0}; Path=/' .format(security.make_user_cookie(username))) self.redirect('/welcome')
def change_pw(self): error = False # success = False # Collect user input for old and new password params = dict(old_pw=self.request.get("old_pw"), new_pw=self.request.get("new_pw"), new_pw_again=self.request.get("new_pw_again")) # Validate if old password is correct if not security.validate_pw(params["old_pw"], self.user.password_hash): params[ "error_pw"] = "Unfortunately, the old password was incorrect." error = True # Validate that new password is in line with platform specifications elif not databases.User.valid_password(params["new_pw"]): params["error_pw"] = "Unfortunately, this is not a valid password." error = True # Validate that both new passwords are equal elif params["new_pw"] != params["new_pw_again"]: params[ "error_pw"] = "Unfortunately, both new passwords didn't match." error = True # Handle user password inputs if error: self.render("settings.html", **params) else: self.user.password = params["new_pw"] self.user.password_hash = security.make_pw_hash(params["new_pw"]) self.user.put() params[ "success_pw"] = "Your password has successfully been changed." self.render("settings.html", **params)
def create_guest(cls): new_guest = cls(username="******", password_hash=security.make_pw_hash("guest"), birthday=datetime.date.today(), avatar="guest-reg.jpg") new_guest.put()
def post(self): username = self.request.get('username') password_1 = self.request.get('password') password_2 = self.request.get('verify') email = self.request.get('email') USER_RE = re.compile(r"^[a-zA-Z0-9_-]{3,20}$") PASSWORD_RE = re.compile(r"^.{3,20}$") EMAIL_RE = re.compile(r"^[\S]+@[\S]+\.[\S]+$") # error checking username_err = "" password_1_err = "" password_2_err = "" email_err = "" if USER_RE.match(username) is None: username_err = "That is not a valid username" if PASSWORD_RE.match(password_1) is None: password_1_err = "That is not a valid password" if password_1 != password_2: password_2_err = "The two passwords do not match" if email: if EMAIL_RE.match(email) is None: email_err = "That is not a valid email address" else: email_err = "" # check if any items are invalid if email: valid = (USER_RE.match(username) and PASSWORD_RE.match(password_1) and (password_1 == password_2) and EMAIL_RE.match(email)) else: valid = (USER_RE.match(username) and PASSWORD_RE.match(password_1) and (password_1 == password_2)) if valid: user_id_hash = security.make_secure_val(username) self.response.set_cookie('user_id', value=user_id_hash, expires=(datetime.datetime.today() + datetime.timedelta(weeks=520)), path='/', # domain='ghufran-syed.appspot.com', # secure=True, # httponly=False ) user_obj = User() user_obj.user_id = user_id_hash user_obj.password = security.make_pw_hash(username, password_1) if email: user_obj.email = email user_obj.put() self.redirect("/") else: form_params["username"] = username form_params["email"] = email form_params["username_err"] = username_err form_params["password_1_err"] = password_1_err form_params["password_2_err"] = password_2_err form_params["email_err"] = email_err self.render("signup.html", **form_params)