Ejemplo n.º 1
0
    def setUp(self):

        now = datetime.datetime.now()
        UserProfile.objects(username='******').update(
            upsert=True,
            set__username='******',
            set__password=
            '******',
            last_login=now,
        )
        self.login('123', '15d77445c11f15134e765d6acaea7a68')
Ejemplo n.º 2
0
 def put(self):
     req = pwd_parser.parse_args(strict=True)
     user_obj = UserProfile.objects(username=req["userName"]).first()
     if user_obj and user_obj.check_password(req["oldPwd"]):
         user_obj.set_password(req["newPwd"])
         return make_response()
     else:
         return make_response(status=const.AUTH_ERROR)
Ejemplo n.º 3
0
 def post(self):
     req = user_parser.parse_args(strict=True)
     user_obj = UserProfile.objects(username=req["username"]).first()
     if user_obj and user_obj.check_password(req["password"]):
         login_user(user_obj, remember=True)
         return make_response()
     else:
         return make_response(status=const.AUTH_ERROR)
Ejemplo n.º 4
0
def insert(username, password):
    obj = UserProfile.objects(username=username).first()
    print("账号:{}".format(username))
    pass_hashed = get_password(password)
    # pass_save = flask_bcrypt.generate_password_hash(pass_hashed)

    if obj:
        obj.set_password(password=pass_hashed)
    else:
        obj = UserProfile(username=username).save()
        obj.set_password(password=pass_hashed)
    print("密码:{}".format(password))
    return 0
Ejemplo n.º 5
0
    def tearDown(self):

        self.logout()
        UserProfile.objects(username='******').delete()
Ejemplo n.º 6
0
def load_user(user_id):
    return UserProfile.objects(id=user_id).first()