Beispiel #1
0
 def post(self, error_msg=None):
     email = self.request.get("email")
     username = self.request.get("username")
     users = User.all().filter('email', email)
     user = User()
     user.email = email
     user.username = username
     user.fullname = self.request.get("firstname")+" "+self.request.get("lastname")
     user.birthday = datetime.datetime.strptime(self.request.get("birthday"), '%Y-%m-%d')
     user.set_password(self.request.get("password")) #set password. need encrypt. 
     user.firstname = self.request.get("firstname")
     user.lastname = self.request.get("lastname")
     user.country = self.request.get("country")
     gender = self.request.get("gender")
     if gender:
         gender_ = str(gender)[0:1]
         user.gender = gender_
     if users.count() == 0:
         user.put()
         #init() the session
         sessions.Session().login_user(user)
         self.redirect("/")
         return
     else:
         error_msg = "That email address has already been registered."
     template_values = {
        "temp_user": user,
        "error": error_msg
     }
     self.generate('signup.html',template_values)
Beispiel #2
0
    def get(self):
        args = self.args_to_dict()
    
        s = {}
        self.session = sessions.Session()
        if self.session['openid_stuff']:
            try:
                s = pickle.loads(str(self.session['openid_stuff']))
            except:
                pass
    
        consumer = Consumer(s, store.DatastoreStore())
        if not consumer:
            return
        fetchers.setDefaultFetcher(fetcher.UrlfetchFetcher())
        auth_response = consumer.complete(args, self.request.uri)
        if auth_response.status == 'success':
            openid = auth_response.getDisplayIdentifier()

            #when user add openid from profile setting, just return status.
            if self.session['openid_userid']:
                user = User.get(self.session['openid_userid'])
                if user:
                    users = User.all().filter('openids', openid)
                    if users.count() == 0:
                        user.openids += [db.Category(openid.strip().encode('utf8'))]
                        user.put()
                    else:
                        msg = "OpenID had already been attached to another user."
                        if users.count()==1 and users.get() == user:
                            msg = "OpenID had already been attached to you."
                        self.generate('user/user_profile_openid_verify.html',
                                      {"status":"fail","msg":msg})
                        return
                self.generate('user/user_profile_openid_verify.html',
                              {"status":"success","msg":"Attach OpenID to user successfully."})
                return

            sreg_data = sreg.SRegResponse.fromSuccessResponse(auth_response)
            users = User.all().filter('openids', openid)
            if users.count() == 0:
                user = User()
                user.openids = [db.Category(openid.strip().encode('utf8'))]
                if sreg_data:
                    user.username = sreg_data["nickname"]
                    user.fullname = sreg_data["fullname"]
                    user.country = sreg_data["country"]
                    user.birthday = datetime.datetime.strptime(sreg_data["dob"], '%Y-%m-%d')
                    user.gender = sreg_data["gender"]
                    user.language = sreg_data["language"]
                    user.postcode = sreg_data["postcode"]
                    #user.email = sreg_data["email"]
                else:
                    user.username = openid
                user.put()
                self.session.login_user(user)
                self.redirect('/user')
                return
            else:
                user = users[0]

            self.session.login_user(user)
            self.redirect('/')
            return
        else:
            #when user add openid from profile setting, just return status.
            if self.session['openid_userid']:
                self.generate('user/user_profile_openid_verify.html',
                              {"status":"fail","msg":"Attach OpenID to user unsuccessfully: OpenID verification failed."})
                return
            self.show_main_page('OpenID verification failed.')