示例#1
0
    def put(self):
        
        json = request.json
        if json['uid']:
            
            record=MetaUser.query.filter_by(user_uid = json['uid']).first()
            user = User.query.filter_by( uid = json['uid'], active=1).first()

            #Ignore iterate, salt, time will not be use this time we just need the encrypted password
            new_password,_,_,_=encrypt_with_interaction( json['password'],
                                                         random_salt=record.product,
                                                         iterate=record.iteraction,
                                                         t=record.modified_on )
            

            
            current_password = user.password
            

            if current_password != new_password:
                #Create a new salted password
                new_password,iterate,t,random_salt = encrypt_with_interaction(json['password'])
                #Now inactive all token related to the user so we can asked him to login again
                Token.query.filter_by(user_uid = json['uid']).update( dict ( active = 0 ))

                #Overwrite the meta user information of the password
                meta_user = MetaUser.query.filter_by( user_uid = json['uid'] )
                meta_user.iteraction = iterate
                meta_user.product = random_salt
                meta_user.modified_on = t
                user.password = new_password
            
            user.pincode = json['pincode']
             
            db.session.commit()
            

        return self.put_response()
示例#2
0
def validate_user():
    if request.json:
        (username,password)=request.json['username'],request.json['password'] 
    else:
        (username,password)=request.form['username'],request.form['password']

    if not password or not username:
        abort(400, 'Password or user cannot be empty')


    user = User.query.filter_by( username = username ).first()

    if not user:
        return user

    meta_user = MetaUser.query.filter_by( user_uid = user.uid ).first()
    #record=db.get("select iteraction,product,modified_on from meta_users where user_uid=%s",record_user.uid,)

    #Ignore iterate, salt, time will not be use this time we just need the encrypted password
    password,_,_,_=encrypt_with_interaction(password,random_salt=meta_user.product,iterate=meta_user.iteraction,t=meta_user.modified_on)

    if  password==user.password:
        return create_user_from_record(user)
示例#3
0
 def object_from_json(self,uid,json):
     password,iterate,t,random_salt=encrypt_with_interaction(json['password'])
     user = User(uid,json['username'],password,json['pincode'])
     meta_user = MetaUser(uid, iterate, random_salt,t)
     return [user,meta_user]