当前位置: 首页>>代码示例>>Python>>正文


Python user.UserModel类代码示例

本文整理汇总了Python中models.user.UserModel的典型用法代码示例。如果您正苦于以下问题:Python UserModel类的具体用法?Python UserModel怎么用?Python UserModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

 def delete(self, user_id):
     try:
         UserModel.delete_by_id(self.db, user_id)
         self.finish_json()
     except Exception, e:
         print e
         self.finish_json(errcode=200, errmsg=str(e))
开发者ID:icyCloud,项目名称:test_p_o_i,代码行数:7,代码来源:user.py

示例2: put

    def put(self, user_id):
        data = json_decode(self.request.body)

        if not self.valid_new_user(data['username'], data['password'], data['nickname'], data['department'], data['permission']):
            self.finish_json(errcode=400, errmsg='wrong argument')
            return
        else:
            user = UserModel.get_user_by_id(self.db, user_id)
            if user is None:
                self.finish_json(errcode=404, errmsg="user id not exist")
                return
            else:

                tmp_user = UserModel.get_user_by_username(
                    self.db, data['username'])
                if tmp_user and (tmp_user.id != int(user_id)):
                    print 'exist username'
                    self.finish_json(errcode=409, errmsg="username exist")
                    return

                try:
                    UserModel.update_by_id(self.db, user_id, data['username'], data[
                                           'password'], data['nickname'], data['department'], data['permission'])
                    self.finish_json()
                    return
                except Exception, e:
                    print e
                    self.finish_json(errcode=507, errmsg=str(e))
                    return
开发者ID:icyCloud,项目名称:test_p_o_i,代码行数:29,代码来源:user.py

示例3: put

    def put(self):
        args = self.get_json_arguments()
        old_password, password, re_password = get_and_valid_arguments(args, 'old_password', 'password', 're_password')

        old_password = md5_password(old_password)
        if self.current_user.password != old_password:
            print u'密码不对'
            print self.current_user.password, old_password
            self.finish_json(1, u'旧密码不正确')
            return

        if (not password) or (not re_password):
            print u'请输入正确密码'
            self.finish_json(1, u'请输入正确密码')
            return

        if password != re_password:
            print u'两次密码不一致'
            self.finish_json(1, u'两次密码不一致')
            return

        if md5_password(password) == self.current_user.password:
            print u'新密码和旧密码相同'
            self.finish_json(1, u'新密码和旧密码相同')
            return

        UserModel.update_password(self.db, self.current_user.merchant_id, self.current_user.username, password)

        self.clear_cookie('username')
        self.clear_cookie('merchant_id')
        self.finish_json(0, '修改成功')
开发者ID:icyCloud,项目名称:test_e_b_k,代码行数:31,代码来源:password.py

示例4: get

 def get(self,uid):
     user_model = UserModel()
     book_model = BookModel()
     info = user_model.get_user(uid)
     current = book_model.get_current(uid)
     data = {}
     current_list = []
     for book in current:
       item = {}
       item["rent_time"] = book[0].date()
       item["return_time"] = book[1].date()
       item["title"] = book[2]
       item["images"] = book[3]
       item["author"] = book[4]
       item["isbn"] = book[5]
       item["address"] = book[6]
       current_list.append(item)
     data["current"] = current_list
     uinfo = {}
     for user in info:
       uinfo["name"] = user[0]
       uinfo["gravator"] = user[1]
       uinfo["major"] = user[2]
       uinfo["degree"] = user[3]
       uinfo["num"] = user[4]
       uinfo["id"] = user[5]
     data["uinfo"] = uinfo
     self.render("user.html",data=data)
开发者ID:huip,项目名称:mylibrary,代码行数:28,代码来源:user.py

示例5: post

 def post(self):
    number = self.get_argument("number")
    passwd = self.get_argument("passwd")
    select = self.get_argument("select")
    user = {"number": number} # user info object
    post = {
        "number": number,
        "passwd": passwd,
        "select": select
        }
    user_model = UserModel()
    user = user_model.get_info(post["number"])
    # 判断用户是否已经存在
    if not user:
      user = User(post).import_user() # import users 
      book_model = BookModel()
      if user_model.import_user(user,post["number"]):
        user = user_model.get_info(user["number"])
        # 判断用户是否已经导入数据
        if book_model.is_import(user["id"]):
          book = Book(post).get_remote_book(True)
        else:
          book = Book(post).get_remote_book(False)
        book_model.import_book(book,user["id"])
      # 将用户信息存入cookie
      self.set_current_user(user)
    self.write(json.dumps({"error_code":"200"}))
开发者ID:huip,项目名称:mylibrary,代码行数:27,代码来源:user.py

示例6: seed

def seed():
  wipe()
  if not UserModel.exists():
    UserModel.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)
  if not Connection.exists():
    Connection.create_table(read_capacity_units=1, write_capacity_units=1, wait=True)
  return "Done!"
开发者ID:imouton,项目名称:pourag,代码行数:7,代码来源:pourag.py

示例7: calc_new_trust

 def calc_new_trust(self):
     winner    = AnswerModel.get_by_answer_id(self.best_answer_id)
     loser     = AnswerModel.get_by_answer_id(self.other_answer_id)
     new_trust = UserModel.newTrust(winner.userID, loser.userID)
     UserModel.setTrust(winner.userID,new_trust[0])
     UserModel.setTrust(loser.userID,new_trust[1])
     
开发者ID:klaplong,项目名称:SWE_2013_Groep2,代码行数:6,代码来源:answerchoice.py

示例8: insert_user

 def insert_user(self, request):
     current_user = endpoints.get_current_user()
     if current_user is None:
         raise endpoints.UnauthorizedException('Authorization required')
     
     logging.info('user '+str(current_user))
     user_id = (current_user.user_id() if current_user is not None and current_user.user_id() is not None
              else 'Anonymous')
     email = (current_user.email() if current_user is not None
              else '[email protected]')
     query = UserModel.query(UserModel.email == email).fetch()
     logging.info('LEN '+str(len(query)))
     userDb = None
     if len(query) > 0:
         userDb = query[0]
         logging.info('DB '+str(userDb))
     else:
         userDb = UserModel(user_id=user_id , email=email)
         userDb.key = ndb.Key('UserModel',email)
         userDb.put()
     
     key = userDb.key.urlsafe()
     #key = userDb.key.id()
     user = User(user_id=userDb.user_id,
                 email=userDb.email,
                 key=str(key))
     
     return user
开发者ID:jmn8718,项目名称:gae-endpoint-app,代码行数:28,代码来源:backend_api.py

示例9: post

    def post(self):
        data = UserRegister.parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {"message": "User with that username already exists."}, 400
        user = UserModel(**data)
        user.save_to_db()
        return {"message": "User created successfully."}, 201
开发者ID:harrysoer,项目名称:flask-api,代码行数:8,代码来源:user.py

示例10: post

    def post(self):
        data = _user_parser.parse_args()

        if UserModel.find_by_username(data['username']):
            return {"message": "A user with that username already exists"}, 400

        user = UserModel(data['username'], data['password'])
        user.save_to_db()

        return {"message": "User created successfully."}, 201
开发者ID:kpgdsc,项目名称:rest-api-sections,代码行数:10,代码来源:user.py

示例11: render

    def render(self):
        if self.debug:
            return render_template('index_debug.html',
                                   lti_dump=g.lti.dump_all())
        if g.lti.is_instructor():
            return render_template('question_list.html')
        else:
            UserModel.save(g.lti.get_user_id(), g.lti.get_user_name())

        return render_template('index_student.html')
开发者ID:klaplong,项目名称:SWE_2013_Groep2,代码行数:10,代码来源:index.py

示例12: post

    def post(self):
        args = self.get_json_arguments()
        merchant_id, username, password, re_password, department, mobile, authority, is_valid = \
            get_and_valid_arguments(
                args, 'merchant_id', 'username', 'password', 're_password', 'department', 'mobile',
                'authority', 'is_valid')

        hotel_id = None
        if 'hotel_id' in args:
            hotel_id = args['hotel_id']
            try:
                hotel_id = int(hotel_id)
                authority = 0
                authority += PERMISSIONS.update_order
                authority += PERMISSIONS.view_cooperated_hotel
                authority += PERMISSIONS.view_order
                authority += PERMISSIONS.inventory
                authority += PERMISSIONS.pricing
                authority += PERMISSIONS.update_password
            except Exception:
                self.finish_json('1', u'不合法的酒店')
                return

        if merchant_id != self.current_user.merchant_id:
            self.finish_json(1, u'您只能管理自己的酒店')
            return
        if not username:
            self.finish_json(1, u'请填写用户名')
            return
        if (not password) or (not re_password):
            self.finish_json(1, u'请输入密码')
            return
        if password != re_password:
            self.finish_json(1, u'两次密码不一致')
            return
        if not department:
            self.finish_json(1, u'请输入部门')
            return
        if not mobile:
            self.finish_json(1, u'请输入手机号')
            return
        if authority & PERMISSIONS.admin or authority & PERMISSIONS.root:
            self.finish_json(1, u'不允许添加管理员用户')
            return

        user = UserModel.get_user_by_merchantid_username(
            self.db, merchant_id, username)

        if user:
            self.finish_json(1, u'用户名已被使用')
        else:
            UserModel.add_user(self.db, merchant_id, username,
                               password, department, mobile, authority, is_valid, hotel_id)
            self.finish_json(0, u'添加成功')
开发者ID:icyCloud,项目名称:test_e_b_k,代码行数:54,代码来源:user.py

示例13: modify_merchant

    def modify_merchant(self, id, name, type, admin_pwd, root_pwd):
        merchant = MerchantModel.get_by_id(self.db, id)
        if not merchant:
            raise JsonException(errcode=404, errmsg="merchant not fount")
        else:
            merchant.update(self.db, name, type)

        if admin_pwd:
            UserModel.update_password(self.db, merchant.id, 'admin', admin_pwd)
        if root_pwd:
            UserModel.update_password(self.db, merchant.id, 'root', root_pwd)

        return merchant
开发者ID:icyCloud,项目名称:test_e_b_k,代码行数:13,代码来源:merchant.py

示例14: put

    def put(self):
        args = self.get_json_arguments()
        merchant_id, username, department, mobile, authority, is_valid = \
            get_and_valid_arguments(
                args, 'merchant_id', 'username', 'department', 'mobile', 'authority', 'is_valid')

        hotel_id = None
        if 'hotel_id' in args:
            hotel_id = args['hotel_id']
            try:
                authority = None
                hotel_id = int(hotel_id)
            except Exception:
                self.finish_json('1', u'不合法的酒店')
                return
        if 'email' in args:
            email = args['email']
        else:
            email = None

        if 'password' in args:
            password = args['password']
        else:
            password = None

        if not self.mobile_check(mobile):
            self.finish_json(1, u'请填写正确手机号')
            return

        if not department:
            self.finish_json(1, u'请填写部门')
            return

        if self.current_user.merchant_id != merchant_id:
            self.finish_json(1, u'您只能管理自己的酒店')
            return

        ''' 可以管理用户 '''
        UserModel.update_user(self.db, merchant_id, username,
                              password, department, mobile, email, is_valid, authority, hotel_id)

        ''' 修改了自己的密码 '''
        if self.current_user.username == username and password:
            self.clear_cookie('username')
            self.clear_cookie('merchant_id')
            self.finish_json(301, self.get_login_url())
            return

        self.finish_json(0, u'成功')
开发者ID:icyCloud,项目名称:test_e_b_k,代码行数:49,代码来源:user.py

示例15: add_user

def add_user(user):
    logging.info("user " + str(user))
    user_id = user.user_id() if user is not None and user.user_id() is not None else "Anonymous"
    email = user.email() if user is not None else "[email protected]"
    query = UserModel.query(UserModel.email == email).fetch()
    logging.info("LEN " + str(len(query)))
    userDb = None
    if len(query) > 0:
        userDb = query[0]
        logging.info("DB " + str(userDb))
    else:
        userDb = UserModel(user_id=user_id, email=email)
        userDb.key = ndb.Key("UserModel", email)
        userDb.put()
    return userDb
开发者ID:jmn8718,项目名称:gae-endpoint-app,代码行数:15,代码来源:public.py


注:本文中的models.user.UserModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。