def register(self): #make sure the user doesn't already exist u = User.by_name(self.username) if u: msg = 'That user already exists.' self.render('signup.html', error_username = msg) else: if self.email: recently_add_user = User.register(self.username, self.password, self.email) else: recently_add_user = User.register(self.username, self.password) #save user to db and login user recently_add_user.put() self.login(recently_add_user) #redirect to home page self.redirect('/')
def initialize(self, *a, **kw): webapp2.RequestHandler.initialize(self, *a, **kw) uid = self.read_secure_cookie('user_id') self.user = uid and User.by_id(int(uid)) self.uid = uid if self.request.url.endswith('.json'): self.format = 'json' else: self.format = 'html'
def post(self): username = self.request.get('username') password = self.request.get('password') u = User.login(username, password) if u: #self.username = u.username self.login(u) self.redirect('/') else: msg = 'Invalid login' self.render('login.html', error = str(u))