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


Python user.User类代码示例

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


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

示例1: login

def login():
    msg = None
    remember = False
    if request.method == "POST" and "username" in request.form:
        username = request.form["username"]
        password = request.form["password"]
        if "remember" in request.form:
            remember = True
        print "remember %s" % remember
        user = User(username)
        if getattr(app, 'fakelogin', False):
            sigel = "NONE"
        else:
            sigel = user.authorize(password, app.config)
        if sigel == None:
            sigel = ""
            msg = u"Kunde inte logga in. Kontrollera användarnamn och lösenord."
        else:
            user.sigel = sigel
            session['sigel'] = sigel
            login_user(user, remember)
            session.permanent = remember
            print "User logged in"
            print "User %s logged in with sigel %s" % (user.username, user.sigel)
            return redirect("/")
    return render_template("partials/login.html", msg = msg, remember = remember)
开发者ID:linawesterling,项目名称:kitin,代码行数:26,代码来源:kitin.py

示例2: decorated_function

 def decorated_function(*a,**kw):
     u = User()
     u.name = session.get('name', None)
     u = get_user(u)
     if not u or not u.isbaron:
         return render_template("not_baron.html", user=get_user_by_name(session.get('name'))), 401
     return fn(*a, **kw)
开发者ID:ulrichknecht,项目名称:baroness,代码行数:7,代码来源:check_rights.py

示例3: test_login_fails_and_returns_false_with_invalid_username_or_password

 def test_login_fails_and_returns_false_with_invalid_username_or_password(self):
     user1 = User("br", "admin")
     user2 = User("tst", "wrongpass")
     file_input = ["bkr,admin,brennon rogers", "tst,admin2,test entry"]
     portal_db_reader = PortalDBReader(file_input)
     self.assertFalse(user1.login(portal_db_reader))
     self.assertFalse(user2.login(portal_db_reader))
开发者ID:Cuddlemuffin007,项目名称:admin_portal,代码行数:7,代码来源:user_tests.py

示例4: post

    def post(self):
        try:
            body = json.loads(self.request.body)
            name = body['name']
            pw = body['pw']
            target_url = body.get('next')
        except (KeyError, ValueError, TypeError) as e:
            self.application.log.info('User creation request malformed, error={}, url={}, body={}'.format(e, self.request.uri, self.request.body))
            self.send_error(httplib.BAD_REQUEST)
            return

        exists = yield User.exists(name)
        if exists:
            self.send_error(httplib.CONFLICT)
            return

        user = User(name, pw)
        yield user.save()
        self.set_current_user(user.guid)
        if target_url:
            self.redirect(target_url)
        else:
            self.set_header('Location', self.reverse_url(UserMaintenanceHandler.__name__, user.guid))
            self.write(self.application.user_representation(user))
            self.set_status(httplib.CREATED)
开发者ID:lchapple,项目名称:minterest,代码行数:25,代码来源:api.py

示例5: start

def start(session):
    print("Dividing numbers rounds them to second decimal!")
    points = 0
    username = input("Enter your playername>")
    user = User(name=username, score=points)
    print("Welcome {}! Let the game begin!".format(username))
    last_answer_correct = True
    while(last_answer_correct):
        expression = Expression.generate_expression()
        print("What is the answer to {} {} {}".format(
            expression[0], expression[2], expression[1]))
        answer = input("?>")
        if(float(answer) == expression[3]):
            print("?>Correct!")
            points += 1
        else:
            score = calculate_score(points)
            print("Incorrect! Ending game. You score is: {}".format(score))
            last_answer_correct = False
            if user.score < score:
                user.score = score
                session.query(User).filter(User.name==username).update({"score": score})
    if(session.query(exists().where(User.name == username)).scalar() == 0):
        session.add(user)
    session.commit()
开发者ID:Legena,项目名称:HackBulgaria,代码行数:25,代码来源:interface.py

示例6: get

 def get(self):
     username = self.request.get("user")
     password = self.request.get("password")
     
     self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
     
     if not username or not password:
         # some fields were missing in the request
         self.response.write(json_error('invalid', ''))
     else:
         # check if username exists in db
         query_user = User.query(User.username == username).fetch()
         if query_user:
             # check if password is correct
             query = User.query(ndb.AND(User.username == username, User.pswd == password)).fetch()
             if query:
                 # generate 64 char session cookie and send it back
                 cookie = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(64))
                 session = Session(cookie = cookie, user = username)
                 session.put()
                 self.response.write(login_response('ok', cookie))   
             else: 
                 # password was incorrect
                 self.response.write(json_error('failure', 'password'))
         else:
             # user didn't exist
             self.response.write(json_error('failure', 'user'))
开发者ID:tuvior,项目名称:WhatsFree,代码行数:27,代码来源:login.py

示例7: user_reg

def user_reg(email, password, sex, name):
    from afconfig import af_conf
    email = email.lower()
    if User.is_exist({'email':email}):
        return 6 #'existed user'
    if af_conf['needinvite']:
        if not Invitation.is_exist({'email':email}):
            return 7 #'not invited'
    password = encrypt(password)
    token = unicode(random_string(20), 'utf-8')
    usr = User(attrs={'email':email})
    doc = {
        'sex' : sex,
        'name' : name,
        'password' : password,
        'token' : token,
        'domain' : usr.uid,
        'account_status' : 'unverified',
    }
    usr.set_propertys(**doc)
    
    m_status = email_verification(usr)
    if m_status is False:
        logging.error('+'*30) 
        logging.error('Email send Failed')
        logging.error('%s %s %s' % (email, token, name))
        logging.error('+'*30)
        return 8 #'mail error'
    return 0
开发者ID:Earthson,项目名称:afewords_base,代码行数:29,代码来源:user_utils.py

示例8: monitor

def monitor(sock, data):


    u = User.find_user_by_sock(sock)
    print 'command from:', u.username
    command = data['command']
    room_name = data['destination']

    if command == 'users':
        li = []
        for el in User.users:
            if el.username:
                li.append([el.username, el.network])
        print 'Number users on:', len(li), '---', len(User.users)
        for el in li:
            print el
    if command == 'rooms':
        r = Room.find_room_by_name(room_name)
        try:
            print 'room alias:', r.alias
            print 'room users_name:', adapter(r.users_name)
        except:
            print 'no room'
    if command == 'message':
        u = User.find_user_by_name('[email protected]', 'dev-socialbase')

        info = {"type": "chat", "payload": {"command": "test_user",
                                            "details": str(u)}}

        u.connection.write_message(info)
        print 'B.sended to ', u.username, info
开发者ID:AlexandreProenca,项目名称:chat2.0,代码行数:31,代码来源:manager.py

示例9: friend_list_request_handle

def friend_list_request_handle(con, content_json):
    obj = {}
    friend_list = []
    num = 0
    user = User(content_json["uid"])
    friend_list = user.get_friend_list()

    print "friend_list=", friend_list
    obj["list"] = []
    for i, friend_id in enumerate(friend_list):
        friend_obj = {}
        num += 1
        friend = User(friend_id)
        friend_obj["loginid"] = i
        friend_obj["nickname"] = friend.nickname
        friend_obj["address"] = friend.address
        friend_obj["phone_num"] = friend.phone_num
        friend_obj["sex"] = friend.sex
        friend_obj["signature"] = friend.signature
        friend_obj["mail"] = friend.mail
        friend_obj["online"] = friend.online
        friend_obj["age"] = friend.age
        obj["list"].append(friend_obj)
    obj["friend_num"] = num
    data = json.dumps(obj, indent=4)
    print data

    # 	send_packet(con,0,4,data,len(data))
    packet = wrap_packet(con, 0, 4, data, len(data))
    return packet
开发者ID:destan19,项目名称:pychat,代码行数:30,代码来源:server.py

示例10: __init__

    def __init__(self, retention):
        self.retention = retention

        for x in range(0, self.initial_amount):
            new_user = User()
            new_user.idle = random.random() < retention
            self.users.append(new_user)
开发者ID:lszperling,项目名称:retention_simulation,代码行数:7,代码来源:simulation_generator.py

示例11: _login_user

    def _login_user(self):
        """
        Ask user login
        """

        # send message to arduino to bling the LED
        self._send_message_to_arduino("3")
        self._logger.info("Please enter your email and password to login")
        user = User()
        sys.stdout.write("email: ")
        user._email = sys.stdin.readline()
        sys.stdout.write("password: ")
        password = sys.stdin.readline()

        # hash password
        user._password = hashlib.sha256(password).hexdigest()
        # sync user settings and get back generated id
        user._uuid = self._sync_user_settings(user)
        # save user settings
        if user._uuid == 0:
            self._logger.info("Login failed. Please check your internet and/or serial connection and retry")
            self._login_user()
        elif user._uuid == "none":
            self._logger.info("Login failed")
            self._login_user()
        elif re.compile("[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}").match(user._uuid):
            self._save_user_settings(user)
            self._logger.info("Login successful")

        # send message to arduino to put off LED
        self._send_message_to_arduino("4")
开发者ID:lbsb,项目名称:wybo-working-hours-tracker,代码行数:31,代码来源:client.py

示例12: create_initial_testing_data

 def create_initial_testing_data(self):
     DB.session.add(AccountType(1, u'Cash'))
     DB.session.add(AccountType(2, u'Credit'))
     DB.session.commit()
     account = Account(1, u'Cash', 3, 0)
     user = User('test_username', 'test_password', [])
     user.hash_password('test_password')
     user.accounts = [account]
     DB.session.add(user)
     DB.session.commit()
     DB.session.add(CategoryType(1, u'Income'))
     DB.session.add(CategoryType(2, u'Spending'))
     DB.session.add(TransactionType(1, u'Income'))
     DB.session.add(TransactionType(2, u'Spending'))
     DB.session.add(TransactionType(3, u'Transfer'))
     DB.session.commit()
     DB.session.add(Category(1, u'Sample income category', None, 1))
     DB.session.add(Category(1, u'Sample spending category', None, 2))
     DB.session.add(Category(1, u'Sample child spending category', 2, 2))
     DB.session.add(Currency(1, u'US dollar', 'USD', u'$'))
     DB.session.add(Currency(2, u'Euro', 'EUR', u'€'))
     DB.session.add(Currency(3, u'Ukrainian hryvna', 'UAH', u'₴'))
     DB.session.add(Currency(4, u'British pound', 'GBP', u'£'))
     DB.session.add(Currency(5, u'Russian ruble', 'RUB', u'₽'))
     DB.session.commit()
开发者ID:dadbob,项目名称:Accounting.API,代码行数:25,代码来源:repository.py

示例13: fun_invite_reg

def fun_invite_reg(email, pwd, sex, name):
    tmp = User.is_exist(email=email)
    if tmp is True:
        return [1,'邮箱已经被注册!']
    AFW_Group = BasicGroup(_id=AFWConfig.afewords_group_id)
    tmp_email = email.replace(r'.', r'#')
    if AFW_Group.invitation_lib[tmp_email] is None:
        return [1, '很抱歉您并未被邀请!']
    af_pwd = encrypt(pwd)
    af_random = random_string(20)
    token = unicode((af_pwd + af_random), "utf-8")
    usr = User()
    usr.set_propertys(**{'email':email, 'sex':sex, 'name':name, 'token':token, 'domain':unicode(usr._id)})
    tmp_avatar = usr.avatar
    tmp_avatar.thumb_name = '/static/avatar/small/afewords-user.jpg'

    #print 'beta.afewords.com/check?email=', email, '&token=',token
    mail_ok, mail_info = send_mail_reg(email, token, name)
    if mail_ok == 1:
        logging.error('+'*30) 
        logging.error('Email send Failed')
        logging.error('%s %s %s' % (email, token, name))
        logging.error('+'*30)
        return [1,'验证邮件发送失败!']
    else:
        return [0, '']
开发者ID:deju,项目名称:afw_old,代码行数:26,代码来源:AF_LoginTool.py

示例14: post

    def post(self):
        """ Handle the sign-up request. """
        email = self.request.get("email")
        pwd = self.request.get("password")
        verify = self.request.get("verify")

        # there is verification on browser by JS, but validating again won't hurt
        if not self._validate(email, pwd, verify):
            logging.error("How could the invalid input pass the JS test? @auth.SignUpHandler.post()")
            self.redirect("/signup")
            return

        if User.exists(email):
            # telling user that the email has been taken
            self._error("Email registered by others")
        else:
            hashed = encrypt.hash_pwd(email, pwd)
            u = User(email=email,
                     pwd_hashed=hashed,
                     parent=utils.get_key_public('User'))
            u.put()
            self._init_user(u)

            self._set_id_cookie(email)
            self.redirect('/me')
开发者ID:AndriyLin,项目名称:Books,代码行数:25,代码来源:__init__.py

示例15: _sync_user_credentials

    def _sync_user_credentials(self, data, addr):
        """
        Received user credentials and send its uuid
        :param data: data send by client
        :param addr: client address
        """

        self._logger.debug("User trying to login from %s", addr[0])
        self._logger.debug("Checking credentials...")
        # format user information received
        data.replace("\n", "")
        user = User()
        user._email = data.split(":")[0]
        user._password = data.split(":")[1]

        # search user
        user_found = self._find_user(user)

        if user_found != None:
            # send the generated uuid to client
            self._socket.sendto(user_found._uuid, (addr[0], addr[1]))
            self._logger.debug("User found")
            self._logger.debug("User (email: %s) is logged", user_found._email)
            self._logger.debug("UUID: \"%s\" sent to %s", user_found._uuid, addr[0])
        else:
            # send empty string to client
            self._socket.sendto("none", (addr[0], addr[1]))
            self._logger.debug("none string sent to %s", addr[0])
            self._logger.debug("User not found")
            self._logger.debug("User (email: %s) failed to login", user._email)
开发者ID:lbsb,项目名称:wybo-working-hours-tracker,代码行数:30,代码来源:server.py


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