Exemple #1
0
    def recoverpw(self):
        email = self.get_post('em', '')
        
        if not mail.is_email_valid(email):
            self.respond("0Please enter a valid e-mail address."); return
        
        # find the user from e-mail
        email = email.lower()
        user = User.get_by_auth_id(auth_id='own:' + email)        
        if user:
            game_name = webapp2.get_app().config['APP_INFO']['NAME']
            game_url = webapp2.get_app().config['APP_INFO']['URL']
            new_pass = security.generate_random_string(length=5)
            user.password = security.generate_password_hash(new_pass, length=12)
            try:                
                user.put()
            except:
                self.respond("0Password recovery failed. Please try again later.")
                return                

            subject = game_name + " login password recovery"
            body = """
Dear %s

This is an automated response. A request was made for your login password used with %s

Your new password is: %s

Use this new password to login to the game. You may change the password in your profile section.
For more information, visit %s

Thank you
""" % (user.name, game_name, new_pass, game_url)

            # send the email via tasqueue so this request can return now and not wait for mail api
            taskqueue.add(queue_name='prioritymail', url='/work/mailer/', params={
                        'email':email,
                        'subject':subject,
                        'body':body,
                        })
            
            if webapp2.get_app().debug:            
                self.respond("1<pre>"+body+"</pre>")
            else:
                self.respond("1")
            return
        
        else:
            self.respond("0We do not have a record of that e-mail address. You may register to join this game.")
            return
        
        self.respond("0")