Пример #1
0
 def get(self):
     username = self.request.get("username")
     email = self.request.get("email").strip()
     if email:
         u = generic.UnverifiedUsers.query(generic.UnverifiedUsers.email == email).get()
         if u:
             email_messages.send_verify_email(u)
             self.redirect("signup?info=A message has been sent to your email, please follow the instructions provided there.")
             return
     h = self.request.get("h")
     self.log_read(generic.UnverifiedUsers)
     u = generic.UnverifiedUsers.query(generic.UnverifiedUsers.username == username).get()
     if not u:
         logging.warning("Handler VerifyEmailPage attempted to verify an email not in Datastore.")
         self.error(404)
         return 
     if generic.hash_str(username + u.salt) == h:
         new_user = generic.RegisteredUsers(username = u.username,
                                            password_hash = u.password_hash,
                                            salt = u.salt,
                                            email = u.email,
                                            about_me = '',
                                            my_projects = [],
                                            profile_image_url = "https://secure.gravatar.com/avatar/" + hashlib.md5(u.email.strip().lower()).hexdigest())
         self.log_and_put(new_user)
         self.log_and_delete(u)
         self.set_cookie("username", new_user.username, new_user.salt, max_age = LOGIN_COOKIE_MAXAGE)
         self.render("email_verified.html")
     else:
         logging.warning("Handler VerifyEmailPage attempted to verify an email with the wrong hash.")
         self.error(404)
         return
Пример #2
0
 def get(self):
     username = self.request.get("username")
     email = self.request.get("email").strip()
     if email:
         u = generic.UnverifiedUsers.query(
             generic.UnverifiedUsers.email == email).get()
         if u:
             email_messages.send_verify_email(u)
             self.redirect(
                 "signup?info=A message has been sent to your email, please follow the instructions provided there."
             )
             return
     h = self.request.get("h")
     self.log_read(generic.UnverifiedUsers)
     u = generic.UnverifiedUsers.query(
         generic.UnverifiedUsers.username == username).get()
     if not u:
         logging.warning(
             "Handler VerifyEmailPage attempted to verify an email not in Datastore."
         )
         self.error(404)
         return
     if generic.hash_str(username + u.salt) == h:
         new_user = generic.RegisteredUsers(
             username=u.username,
             password_hash=u.password_hash,
             salt=u.salt,
             email=u.email,
             about_me='',
             my_projects=[],
             profile_image_url="https://secure.gravatar.com/avatar/" +
             hashlib.md5(u.email.strip().lower()).hexdigest())
         self.log_and_put(new_user)
         self.log_and_delete(u)
         self.set_cookie("username",
                         new_user.username,
                         new_user.salt,
                         max_age=LOGIN_COOKIE_MAXAGE)
         self.render("email_verified.html")
     else:
         logging.warning(
             "Handler VerifyEmailPage attempted to verify an email with the wrong hash."
         )
         self.error(404)
         return
Пример #3
0
 def post(self):
     usern = self.request.get('usern')
     password = self.request.get('password')
     verify = self.request.get('verify')
     email = self.request.get('email')
     have_error = False
     kw = {"usern" : usern, "email" : email, "error" : '', "info" : self.request.get("info")}
     # Valid input
     if usern and (usern.lower() in FORBIDDEN_USERNAMES):
         kw['error_username'] = True
         kw['error'] = "That username is not available"
         have_error = True
     if not re.match(USERNAME_RE, usern):
         kw['error_username'] = True
         kw['error'] += "That's not a valid username, it must be from 3 to 20 characters long, start with a letter and contain only letters, numbers, dashes and underscores. "
         have_error = True
     if not re.match(EMAIL_RE, email):
         kw['error_email'] = True
         kw['error'] += "That doesn't seem like a valid email. "
         have_error = True
     if not re.match(PASSWORD_RE, password):
         kw['error_password'] = True
         kw['error'] += "That's not a valid password, it must be between 3 and 20 characters long. "
         have_error = True
     elif password != verify:
         kw['error_verify'] = True
         kw['error'] += "Your passwords didn't match. "
         have_error = True
     if not have_error:
         usern = usern.lower()
         # Available username
         another_user = self.get_user_by_username(usern, "Checking if username is available")
         if not another_user:
             self.log_read(generic.UnverifiedUsers, "Checking if username is available. ")
             another_user = generic.UnverifiedUsers.query(generic.UnverifiedUsers.username == usern).get()
         if another_user:
             have_error = True
             kw['error_username'] = True
             kw['error'] += 'That username is not available. '
         # Available email
         another_email = self.get_user_by_email(email, "Checking if email is available. ")
         if another_email:
             have_error = True
             kw['error_email'] = True
             kw['error'] += 'That email is already in use by someone. Did you <a href="/recover_password?email=%s">forget your password?. </a>' % email
         else:
             self.log_read(generic.UnverifiedUsers, "Checking if email is available. ")
             another_email = generic.UnverifiedUsers.query(generic.UnverifiedUsers.email == email).get()
             if another_email:
                 have_error = True
                 kw['error_email'] = True
                 kw['error'] = 'This email is already registered but it still needs to be verified, click <a href="/verify_email?email=%s">here</a> to send the verification email again.' % email
     # Render
     if have_error:
         self.render('signup.html', **kw)
     else:
         salt = generic.make_salt()
         ph = generic.hash_str(password + salt)
         u = generic.UnverifiedUsers(username = usern, password_hash = ph, salt = salt, email = email)
         self.log_and_put(u, "New user registration")
         email_messages.send_verify_email(u)
         self.render('signup.html', info = "A message has been sent to your email, please follow the instructions provided there.")
Пример #4
0
 def post(self):
     usern = self.request.get('usern')
     password = self.request.get('password')
     verify = self.request.get('verify')
     email = self.request.get('email')
     have_error = False
     kw = {"usern": usern, "email": email, "error": ''}
     # Valid input
     if usern and (usern.lower() in FORBIDDEN_USERNAMES):
         kw['error_username'] = "******"
         kw['error'] = "That username is not available"
         have_error = True
     if not re.match(USERNAME_RE, usern):
         kw['error_username'] = "******"
         kw['error'] += "That's not a valid username, it must be from 3 to 20 characters long, start with a letter and contain only letters, numbers, dashes and underscores. "
         have_error = True
     if not re.match(EMAIL_RE, email):
         kw['error_email'] = "*"
         kw['error'] += "That doesn't seem like a valid email. "
         have_error = True
     if not re.match(PASSWORD_RE, password):
         kw['error_password'] = "******"
         kw['error'] += "That's not a valid password, it must be between 3 and 20 characters long. "
         have_error = True
     elif password != verify:
         kw['error_verify'] = "*"
         kw['error'] += "Your passwords didn't match. "
         have_error = True
     if not have_error:
         usern = usern.lower()
         # Available username
         another_user = self.get_user_by_username(
             usern, "Checking if username is available")
         if not another_user:
             self.log_read(UnverifiedUsers,
                           "Checking if username is available. ")
             another_user = UnverifiedUsers.query(
                 UnverifiedUsers.username == usern).get()
         if another_user:
             have_error = True
             kw['error_username'] = "******"
             kw['error'] += 'That username is not available. '
         # Available email
         another_email = self.get_user_by_email(
             email, "Checking if email is available. ")
         if another_email:
             have_error = True
             kw['error_email'] = "*"
             kw['error'] += 'That email is already in use by someone. Did you <a href="/recover_password?email=%s">forget your password?. </a>' % email
         else:
             self.log_read(UnverifiedUsers,
                           "Checking if email is available. ")
             another_email = UnverifiedUsers.query(
                 UnverifiedUsers.email == email).get()
             if another_email:
                 have_error = True
                 kw['error_email'] = '*'
                 kw['error'] += 'This email is already registered but it still needs to be verified, click <a href="/verify_email?email=%s">here</a> to send the verification email again.' % email
     # Render
     if have_error:
         self.render('signup.html', **kw)
     else:
         salt = make_salt()
         ph = hash_str(password + salt)
         u = UnverifiedUsers(username=usern,
                             password_hash=ph,
                             salt=salt,
                             email=email)
         self.log_and_put(u, "New user registration")
         email_messages.send_verify_email(u)
         self.render("please_verify_email.html")