def post(self, *args, **kwargs): username = self.get_argument("username") password = self.get_argument("password") name = self.get_argument("name") if UserInfo().counts(username=username): result = False else: UserInfo().create(username=username, password=md5(password), name=name) result = True self.set_secure_cookie("user", username) nav = -2 self.render("default/web-register.html", nav=nav, result=result)
def put(self, *args, **kwargs): userid = kwargs["userid"] user = UserInfo().get(id=userid) name = self.get_argument("name", None) password = self.get_argument("password", None) is_super = self.get_argument("is_super", None) args = {} if name: args["name"] = name if password: args["password"] = password if is_super: args["is_super"] = is_super UserInfo().update("and id=%s" % user["id"], **args) data = {"result":True} self.write(json_encode(data))
def user_info(): auth_header = request.headers.get('Authorization') if auth_header: auth_token = auth_header.split(" ")[1] else: auth_token = '' if auth_token: id = TokenList.query.filter_by(token=auth_token).first() else: return 'Access is forbidden', 403 if request.method == 'PUT': if id: data = request.form info = UserInfo.query.filter_by(user_id=id.user_id).first() if not info: info_add = UserInfo(id.user_id) db.session.add(info_add) db.session.commit() info_add.update_fields(data) else: info.update_fields(data) db.session.commit() responseObj = {'message': 'User info updated'} return make_response(jsonify(responseObj)), 200 else: return 'Access is forbidden', 403 if request.method == 'GET': if id: info = UserInfo.query.filter_by(user_id=id.user_id).first() if info: responseObj = { 'name': info.name, 'surname': info.surname, 'age': info.age } else: responseObj = {'name': '', 'surname': '', 'age': ''} return make_response(jsonify(responseObj)), 200 else: return 'Access is forbidden', 403
def user_create(db: Session, obj_in: UserCreateSchema) -> UserInfo: print(f'ojb_in:{obj_in}') db_obj = UserInfo(username=obj_in.username, user_id=obj_in.user_id, city=obj_in.city, registe_time=obj_in.registe_time, password=obj_in.password) db.add(db_obj) db.commit() db.refresh(db_obj) return db_obj
def post(self, *args, **kwargs): username = self.get_argument("username") password = self.get_argument("password") if UserInfo().counts(username=username, password=md5(password)): result = True self.set_secure_cookie("user", username) next_url = self.get_argument("next",default="/") self.redirect(next_url) else: result = False nav = -2 self.render("default/login.html", nav=nav, result=result)
def get(self, *args, **kwargs): args = {} userlist = UserInfo().filter(**args) counts = UserInfo().counts(**args) data = {"result":True, "data":userlist, "counts":counts} self.write(json_encode(data))
def delete(self, *args, **kwargs): userid = kwargs["userid"] user = UserInfo().get(id=userid) UserInfo().delete(dict(id=user.id)) data = {"result":True} self.write(json_encode(data))
def get(self, *args, **kwargs): userid = kwargs["userid"] user = UserInfo().get(id=userid) counts = 1 data = {"result":True, "data":user, "counts":counts} self.write(json_encode(data))
def get_current_user(self): username = self.get_secure_cookie("user") user = None if username: user = UserInfo().get(username=username) return user