Exemplo n.º 1
0
 def verify_reset_pass_token(token):
     s = TSerializer(app.config['SECRET_KEY'])
     try:
         user_id = s.loads(token)['user_id']
         return User.query.get(user_id)
     except:
         return None
Exemplo n.º 2
0
 def verify_auth_token(token):
     s = TSerializer(current_app.config['SECRET_KEY'])
     try:
         data = s.loads(token)
     except:
         return None
     return User.query.get(data['id'])
Exemplo n.º 3
0
 def load_user_from_auth_token(token):
     s = TSerializer(current_app.config['AUTH_SECRET_KEY'])
     try:
         data = s.loads(token)
     except SignatureExpired:
         return False  #: overtime signature
     except BadSignature:
         return False  #: wrong signature
     user_id = data['_id']
     return User.get_by_id(user_id)
Exemplo n.º 4
0
    def confirm(self, token):
        s = TSerializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False

        if data.get('confirm') != self.id:
            return False
        self.confirm(True)
        db.session.add(self)
        return True
Exemplo n.º 5
0
    def change_email(cls, token):
        s = TSerializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False, "Invalid token"

        user_id = data.get('user_id')
        user = User.query.filter_by(id=user_id).first()
        if user is None:
            return False, "Invalid token - wrong user"
        else:
            user.email = data.get('email')
            return True, user
Exemplo n.º 6
0
    def reset_password(cls, token, password):
        s = TSerializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False, "Invalid token"

        user_id = data.get('reset')
        user = User.query.filter_by(id=user_id).first()
        if user is None:
            return False, "Invalid token - wrong user"
        else:
            user.password = password
            return True, user
Exemplo n.º 7
0
 def generate_auth_token(self, expiration=None):
     if expiration is None:
         expiration = current_app.config['AUTH_TOKEN_EXPIRE']
     s = TSerializer(current_app.config['AUTH_SECRET_KEY'],
                     expires_in=expiration)
     return s.dumps({'_id': self._id})
Exemplo n.º 8
0
 def generate_auth_token(self, expiration):
     s = TSerializer(current_app.config['SECRET_KEY'],
                     expires_in=expiration)
     return s.dumps({'id': self.id}).decode('utf-8')
Exemplo n.º 9
0
 def generate_change_email_token(self, new_email, expiration=3600):
     s = TSerializer(current_app.config['SECRET_KEY'], expiration)
     return s.dumps({'user_id': self.id, 'email': new_email})
Exemplo n.º 10
0
 def generate_reset_token(self, expiration=3600):
     s = TSerializer(current_app.config['SECRET_KEY'], expiration)
     return s.dumps({'reset': self.id})
Exemplo n.º 11
0
 def generate_confirmation_token(self, expiration=2600):
     s = TSerializer(current_app.config['SECRET_KEY'], expiration)
     return s.dumps({'confirm': self.id})
Exemplo n.º 12
0
 def get_reset_pass_token(self, expire_secs=1800):  #30 minutes
     s = TSerializer(app.config['SECRET_KEY'], expire_secs)
     return s.dumps({'user_id': self.id}).decode('utf-8')