當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。