def ibase(self): return { "id": self.id, "name": self.name, "summary": self.summary, "body": self.body, "body_markup": self.body_markup, 'created': rfc3339_string(self.created), 'updated': rfc3339_string(self.updated), }
def iuser(self): return { "name": self.name, "id": self.uid, "body": self.body, "body_markup": self.body_markup, "summary": self.summary, "count": self.count, "created": rfc3339_string(self.created), "updated": rfc3339_string(self.updated), }
def ibase(self): return { "parent": self.parent.isimple if self.parent_id else None, "id": self.uid, "name": self.name, "summary": self.summary, "body": self.body, "body_markup": self.body_markup, 'created': rfc3339_string(self.created), 'updated': rfc3339_string(self.updated), }
def iuser(self): return { "title": self.title, "id": self.uid, "body": self.body, "body_markup": self.body_markup, "abstract": self.abstract, 'created': rfc3339_string(self.created), 'updated': rfc3339_string(self.updated), 'tags': [t.iuser for t in self.tags], 'catalog': self.catalog.iuser if self.catalog_id else None, 'category': self.category.iuser if self.category_id else None, }
def iuser(self): return { "title": self.title, "id": self.uid, "body": self.body, "body_markup": self.body_markup, "abstract": self.abstract, "created": rfc3339_string(self.created), "updated": rfc3339_string(self.updated), "tags": [t.iuser for t in self.tags], "catalog": self.catalog.iuser if self.catalog_id else None, "category": self.category.iuser if self.category_id else None, }
def ibase(self): return { 'id': self.uid, 'username': self.username, 'first_name': self.first_name, 'last_name': self.last_name, 'nickname': self.nickname, 'email': self.email, 'gender': self.gender, 'is_staff': self.is_staff, 'is_superuser': self.is_superuser, 'is_locked': self.is_locked, 'language': self.language, 'last_active': rfc3339_string(self.last_active), 'last_login': rfc3339_string(self.last_login), 'date_joined': rfc3339_string(self.date_joined), }
def ilist_public(self): return { 'id': self.id, 'platform': self.platform.isimple, 'title': self.title, 'abstract': self.abstract, 'price': self.price, 'city': self.city, 'categories': [x.isimple for x in self.categories], 'roles': [x.isimple for x in self.roles], 'skills': [x.isimple for x in self.skills], 'status': self.status, 'view_count': self.view_count, 'vote_up': self.vote_up, 'vote_down': self.vote_down, 'release_date': rfc3339_string(self.release_date), 'expire_date': rfc3339_string(self.expire_date), 'created': rfc3339_string(self.created), 'updated': rfc3339_string(self.updated), }
def post(self): '''用户登录''' form = SignInForm.from_json(self.get_body_json()) if not form.validate(): return self.fail(errors=form.errors) # support username login user = self.db.query(User).filter_by( username=form.username.data).first() # support email login if not user: user = self.db.query(User).filter_by( email=form.username.data).first() # support uid login if not user: try: UID = int(form.username.data) user = self.db.query(User).filter_by(uid=UID).first() except: pass if not user: return self.fail(_("Wrong username or password")) if user.is_locked: return self.fail(_("User is locked")) if not user.is_active: return self.fail(_("User is inactive")) if not user.check_password(form.password.data): return self.fail(_("Wrong username or password")) # 设置其他 user.last_login = datetime.datetime.utcnow() user.last_active = datetime.datetime.utcnow() # 验证成功 session = create_session( self.db, user, from_ip=self.request.remote_ip) self.require_setting("secret_key", "secure key") secret = self.application.settings["secret_key"] sid = create_signed_value( secret, "Sid", session.sid).decode() # TODO: fix me! self.success(sid=sid, expired=rfc3339_string(session.expired))
def post(self): '''用户登录''' form = SignInForm.from_json(self.get_body_json()) if not form.validate(): return self.fail(errors=form.errors) # support username login user = self.db.query(User).filter_by( username=form.username.data).first() # support email login if not user: user = self.db.query(User).filter_by( email=form.username.data).first() # support uid login if not user: try: UID = int(form.username.data) user = self.db.query(User).filter_by(uid=UID).first() except: pass if not user: return self.fail(_("Wrong username or password")) if user.is_locked: return self.fail(_("User is locked")) if not user.is_active: return self.fail(_("User is inactive")) if not user.check_password(form.password.data): return self.fail(_("Wrong username or password")) # 设置其他 user.last_login = datetime.datetime.utcnow() user.last_active = datetime.datetime.utcnow() # 验证成功 session = create_session(self.db, user, from_ip=self.request.remote_ip) self.require_setting("secret_key", "secure key") secret = self.application.settings["secret_key"] sid = create_signed_value(secret, "Sid", session.sid).decode() # TODO: fix me! self.success(sid=sid, expired=rfc3339_string(session.expired))