示例#1
0
    def post(self):
        if request.json:
            try:
                email = request.json['email']
            except IndexError, e:
                return self.send_400("%s is required" % e)
            try:
                user = User.select(User.q.email==email)[0]
            except:
                return self.send_200({"success": True})
            token = ResetToken(user=user)
            msg = Message("Password Reset",
                          sender=(SITE_NAME, "no-reply@%s" % SITE_URL),
                          recipients=[email])
            message = """
            Hello!
            You (hopefully) have requested a password reset for your account at
            {site_name}. In order to complete this reset, please visit:

            {site_url}/reset/?{enc_token}
            """

            msg.body = message.format(site_name=SITE_NAME, site_url=SITE_URL,
                                      enc_token=quote(token.token))
            g.mail.send(msg)
示例#2
0
 def get(self, user_id):
     if user_id is None:
         userlist = [user.dict() for user in User.select()]
         return self.send_200(userlist)
     else:
         try:
             user = User.get(user_id)
         except SQLObjectNotFound:
             return self.send_404()
         else:
             return self.send_200(user.json())
示例#3
0
    def post(self):
        if request.json:
            email = request.json['email']
            password = request.json['password']

            try:
                salted = hashlib.sha256("%s%s" % (salt, password)).hexdigest()
                user = User.select(User.q.email==email)[0]
                if user.password == salted:
                    user.last_login = datetime.now()
                    user_dict = user.dict()
                    user_dict['token'] = user.get_token()
                    return self.send_200(user_dict)
                else:
                    raise SQLObjectNotFound
            except SQLObjectNotFound, IndexError:
                return self.send_401()
示例#4
0
def init_db(config):
    tables = [User, Image, Hop, Grain, Extract, HoppedExtract, AuthToken,
              Yeast, Water, Misc, Mineral, Fining, Flavor, Spice, Herb,
              BJCPStyle, BJCPCategory,  MashTun, BoilKettle, EquipmentSet,
              MashProfile, MashStep, MashStepOrder, Recipe, RecipeIngredient,
              Inventory, ResetToken, Entry, Comment, Tag]
    for table in tables:
            table.createTable(ifNotExists=True)
            if table.__name__ == 'User':
              adef = config['ADMIN_USERNAME']
              try:
                  admin = User(email=adef, first_name=adef,
                               last_name=adef, alias=adef)
              except DuplicateEntryError:
                  admin = User.select(User.q.email==adef)[0]
              admin.set_pass(config['PASSWORD_SALT'], config['ADMIN_PASSWORD'])
              admin.admin = True


    process_bjcp_styles()
    process_bt_database()