Ejemplo n.º 1
0
    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

        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 self.email and not valid_email(self.email):
            params['error_email'] = "That's not a valid email."
            have_error = True

        if have_error:
            self.render('signUp.html', **params)
        else:
            u = User.by_name(self.username)
            if u:
                msg = 'That user already exists.'
                self.render('signUp.html', error_username = msg)
            else:
                if self.email:
                    u = User.register(self.username, self.password, self.email)
                else:
                    u = User.register(self.username, self.password)
                u.put()

                CookieManager.set_secure_cookie('user_id', str(u.key().id()), self.response)
                self.redirect('/blog/welcome?username=' + self.username)
Ejemplo n.º 2
0
 def initialize(self, *a, **kw):
     webapp2.RequestHandler.initialize(self, *a, **kw)
     uid = CookieManager.read_secure_cookie('user_id', self.request)
     self.user = uid and User.by_id(int(uid))