Exemple #1
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')

        logging.info('username = %s, password = %s, verify = %s, email = %s' % (username, password, verify, email))

        params = dict(username = username,
                      email = email)

        has_error = False

        if not validate_username(username):
            params['username_error'] = "That's not a valid username."
            has_error = True

        if not validate_password(password):
            params['password_error'] = "That wasn't a valid password."
            has_error = True
        elif password != verify:
            params['verify_error'] = "Your passwords didn't match."
            has_error = True

        if not validate_email(email):
            params['email_error'] = "That's not a valid email."
            has_error = True

        u = User.by_name(username)

        logging.info("Got user: %s" % u)
        if u:
            params['username_error'] = "The user already exists."
            has_error = True

        if has_error:
            self.render('u4-signup-form.html', **params)
        else:
            # TODO: Do password hashing+salting
            # insert new user into DB
            u = User.register(username, password, email)
            u.put()

            self.login(u)
            self.redirect('/unit4/welcome')
Exemple #2
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')

        logging.info('username = %s, password = %s' % (username, password))

        u = User.login(username, password)
        if u:
            self.login(u)
            self.redirect('/unit4/welcome')
        else:
            msg = 'Invalid login'
            self.render('u4-login-form.html', login_error = msg)