def get(self, verify_code_hash): user_id, user = self.get_user() data = { 'user': user, 'page_title': 'User Verification' } if '/' not in verify_code_hash: self.render('verify_fail.html', **data) return username, verify_code = verify_code_hash.split('/') test_user = User.user_from_name(username) if not test_user: logging.warning('VerifyUser: user not found in db.') self.render('verify_fail.html', **data) return if test_user.verify_code == verify_code: test_user.verified = True test_user.verify_code = None test_user.put() logging.info('VerifyUser: user succesfully verified.') self.render('verify.html', **data) else: self.render('verify_fail.html', **data)
def post(self): email = self.request.get('email', '') password = self.request.get('password', '') other_username = self.request.get('other-user') logging.info('%s, %s' % (email, other_username)) user = User.user_from_email(email) if not user: logging.info('not a valid email address') self.render('error.html', **{'error_msg': 'You cannot do this'}) return if not self.validate_user(user, password): logging.info('username password fail') self.render('error.html', **{'error_msg': 'You cannot do this'}) return if not user.admin: logging.info('Need to be admin to login as other user') self.render('error.html', **{'error_msg': 'You cannot do this'}) return other_user = User.user_from_name(other_username) logging.info('Other user: %s' % other_user) if not other_user: logging.info('cannot find other user') self.render('error.html', **{'error_msg': "Can't find other user"}) return self.set_cookie(other_user) self.redirect('/user/%d' % other_user.key.id())
def input_errors(self, username, password, validate, email): '''Return a list of errors with user registration data.''' # collect error text strings errors = [] # username errors if not username: errors.append('You forgot to enter a username.') logging.warning('Register: forgot username.') elif not self.valid_name(username): errors.append( 'A Valid user name can contain only the characters ' 'a-z, A-Z, 0-9, _ (underscore) and - (dash) and must be at ' 'least 3 characters long.' ) logging.warning('Register: invalid username: %s.', username) user = User.user_from_name(username) if user: # user name already exists errors.append( 'That user name already exists, please choose another one.' ) logging.warning('Register: username already in use. %s', user) # email errors if not email: errors.append('You forgot to enter an email address.') logging.warning('Register: forgot email.') elif not self.valid_email(email): errors.append( 'Check your email address - it may not ' 'be correct.') logging.warning('Register: invalid email: %s', email) else: # maybe the email address is being used by another user - can't # have more than one user with the same email address because the # email address is used as login id user = User.user_from_email(email) if user: # email address is attached to other user errors.append( 'This email address is used by another user.' ) msg = 'Register: email address already in use: %s' logging.warning(msg, email) # password errors if not password or not validate: errors.append('You forgot to enter your password twice.') logging.warning('Register: forgot to enter password twice.') elif password != validate: msg = "Your password confirmation doesn't match your password." errors.append(msg) logging.warning('Register: validate != password.') if not self.valid_pass(password): errors.append( 'Not a valid password - it must contain at least ' '3 characters.') logging.warning('Register: invalid password.') return errors