Example #1
0
def test_login():  # type: () -> None
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()

    user = User()
    user.login('user1_name', 'password')
Example #2
0
def test_login():  # type: () -> None
    user = User()
    user.set("username", "user1_name")
    user.set("password", "password")
    user.login()

    user = User()
    user.login("user1_name", "password")
Example #3
0
 def validate_password(self, field):
     if self.email.data:
         try:
             user = User()
             user.login(self.email.data, self.password.data)
             self.user = user
         except LeanCloudError:
             raise ValueError("密码不正确.")
Example #4
0
def test_refresh_session_token():
    user = User()
    user.set("username", "user1_name")
    user.set("password", "password")
    user.login()
    old_session_token = user.get_session_token()
    user.refresh_session_token()
    assert old_session_token != user.get_session_token()
Example #5
0
def test_refresh_session_token():
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()
    old_session_token = user.get_session_token()
    user.refresh_session_token()
    assert old_session_token != user.get_session_token()
Example #6
0
def test_follower_query():
    user1 = User()
    user1.login('user1_name', 'password')
    user2 = User()
    user2.login('user2_name', 'password')
    user2.follow(user1.id)
    query = User.create_follower_query(user1.id)
    assert query.first().id == user2.id
Example #7
0
def test_login(): # type: () -> None
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()

    user = User()
    user.login('user1_name', 'password')
Example #8
0
def test_follower_query():  # type: () -> None
    user1 = User()
    user1.login("user1_name", "password")
    user2 = User()
    user2.login("user2_name", "password")
    user2.follow(user1.id)
    query = User.create_follower_query(user1.id)
    assert query.first().id == user2.id
Example #9
0
def test_login():
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()

    user = User()
    user.login('user1_name', 'password')
Example #10
0
def test_follower_query():
    user1 = User()
    user1.login('user1_name', 'password')
    user2 = User()
    user2.login('user2_name', 'password')
    user2.follow(user1.id)
    query = User.create_follower_query(user1.id)
    assert query.first().id == user2.id
Example #11
0
def test_login():
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()

    user = User()
    user.login('user1_name', 'password')
Example #12
0
def test_refresh_session_token():
    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()
    old_session_token = user.get_session_token()
    user.refresh_session_token()
    assert old_session_token != user.get_session_token()
Example #13
0
def signin_user(email, password, permenent=True):
    """Sign in user."""
    session.permanent = True

    leanuser = User()
    leanuser.login(email, password)
    token = leanuser.get_session_token()
    session['session_token'] = token
Example #14
0
def test_file_field():  # type: () -> None
    user = User()
    user.login("user1_name", "password")
    user.set("xxxxx", File("xxx.txt", io.BytesIO(b"qqqqq")))
    user.save()

    q = Query(User)
    saved_user = q.get(user.id)
    assert isinstance(saved_user.get("xxxxx"), File)
    assert saved_user.get("xxxxx").name == "xxx.txt"
Example #15
0
def test_file_field():
    user = User()
    user.login('user1_name', 'password')
    user.set('xxxxx', File('xxx.txt', buffer_type(b'qqqqq')))
    user.save()

    q = Query(User)
    saved_user = q.get(user.id)
    assert isinstance(saved_user.get('xxxxx'), File)
    assert saved_user.get('xxxxx').name == 'xxx.txt'
Example #16
0
def test_file_field():  # type: () -> None
    user = User()
    user.login('user1_name', 'password')
    user.set('xxxxx', File('xxx.txt', io.BytesIO(b'qqqqq')))
    user.save()

    q = Query(User)
    saved_user = q.get(user.id)
    assert isinstance(saved_user.get('xxxxx'), File)
    assert saved_user.get('xxxxx').name == 'xxx.txt'
Example #17
0
 def POST(self, _phone, _password):
     user = User()
     try:
         user.login(_phone, _password)
         token = user.get_session_token()
         trueName = user.get("nickName")
         web.setcookie('session', token)
         return {'status': 0, 'token': token, 'name': trueName}
     except leancloud.errors.LeanCloudError:
         return {'status': 1, 'message': 'login failed'}
Example #18
0
def test_file_field():
    user = User()
    user.login('user1_name', 'password')
    user.set('xxxxx', File('xxx.txt', buffer('qqqqq')))
    user.save()

    q = Query(User)
    saved_user = q.get(user.id)
    assert isinstance(saved_user.get('xxxxx'), File)
    assert saved_user.get('xxxxx').name == 'xxx.txt'
Example #19
0
def test_follow():
    user1 = User()
    user1.set('username', 'user1_name')
    user1.set('password', 'password')
    user1.login()

    user2 = User()
    user2.set('username', 'user2_name')
    user2.set('password', 'password')
    user2.login()

    user1.follow(user2.id)
Example #20
0
 def POST(self):
     it = web.input()
     username = it.get('username', '')
     password = it.get('password', '')
     user = User()
     try:
         user.login(username, password)
         token = user.get_session_token()
         web.setcookie('token', token)
         return {'code': 0, 'token': token}
     except leancloud.errors.LeanCloudError:
         return {'code': 1}
Example #21
0
def test_is_authenticated():
    user = User()
    assert not user.is_authenticated()

    user._session_token = 'invalid-session-token'
    assert not user.is_authenticated()

    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()
    assert user.is_authenticated()
Example #22
0
def test_is_authenticated():
    user = User()
    assert not user.is_authenticated()

    user._session_token = 'invalid-session-token'
    assert not user.is_authenticated()

    user = User()
    user.set('username', 'user1_name')
    user.set('password', 'password')
    user.login()
    assert user.is_authenticated()
 def validate_password(self, field):
     user = User()
     try:
         user.login(self.account.data.strip(), self.password.data)
         self.user = user
     except Exception, e:
         if e.code:
             if e.code == 210:
                 raise ValueError('用户名/密码不正确')
             if e.code == 211:
                 raise ValueError('账号不存在')
         raise ValueError('用户名/密码不正确')
Example #24
0
def test_follow():
    user1 = User()
    user1.set('username', 'user1_name')
    user1.set('password', 'password')
    user1.login()

    user2 = User()
    user2.set('username', 'user2_name')
    user2.set('password', 'password')
    user2.login()

    user1.follow(user2.id)
Example #25
0
def test_follow():  # type: () -> None
    user1 = User()
    user1.set("username", "user1_name")
    user1.set("password", "password")
    user1.login()

    user2 = User()
    user2.set("username", "user2_name")
    user2.set("password", "password")
    user2.login()

    user1.follow(user2.id)
Example #26
0
def test_is_authenticated():
    user = User()
    assert not user.is_authenticated()

    user._session_token = "invalid-session-token"
    assert not user.is_authenticated()

    user = User()
    user.set("username", "user1_name")
    user.set("password", "password")
    user.login()
    assert user.is_authenticated()
Example #27
0
def test_get_roles():  # type: () -> None
    role = leancloud.Role('xxx')
    role.save()

    user = User()
    user.login('user1_name', 'password')
    role.get_users().add(user)
    role.save()
    bind_roles = user.get_roles()
    assert len(bind_roles) == 1
    assert bind_roles[0].get('name') == 'xxx'

    role.destroy()
Example #28
0
def test_get_roles():  # type: () -> None
    role = leancloud.Role("xxx")
    role.save()

    user = User()
    user.login("user1_name", "password")
    role.get_users().add(user)
    role.save()
    bind_roles = user.get_roles()
    assert len(bind_roles) == 1
    assert bind_roles[0].get("name") == "xxx"

    role.destroy()
Example #29
0
    def post(self):
        username = self.get_argument("username")
        password = self.get_argument("password")
        try:
            user = User()
            user.login(username, password)
        except leancloud.errors.LeanCloudError as e:
            print(e.code, e.error)

        self.set_secure_cookie("user_id", user.id)
        self.set_secure_cookie("username", username)
        #self.redirect('/')
        self.redirect('/user/')
Example #30
0
def test_get_roles(): # type: () -> None
    role = leancloud.Role('xxx')
    role.save()

    user = User()
    user.login('user1_name', 'password')
    role.get_users().add(user)
    role.save()
    bind_roles = user.get_roles()
    assert len(bind_roles) == 1
    assert bind_roles[0].get('name') == 'xxx'

    role.destroy()
Example #31
0
def login():
    form = LoginForm(request.form)
    if request.method == 'POST' and form.validate_on_submit():
        try:
            u = User()
            u.login(form.username.data, form.password.data)
            data = u.attributes
            data['id'] = u.id
            data['updated_at'] = u.updated_at
            data['created_at'] = u.created_at
            session['user'] = u.attributes
            return redirect(url_for('.index'))
        except LeanCloudError, e:
            flash(e.error, 'danger')
Example #32
0
def test_change_phone_number():  # type: () -> None
    try:
        # phone number is from http://www.z-sms.com
        User.change_phone_number("196784", "+8617180655340")
    except LeanCloudError as e:
        if e.code != 603:
            raise e
    else:
        user1 = User()
        user1.set("username", "py_test_change_phone")
        user1.set("password", "password")
        user1.login()
        assert user1.get_mobile_phone_number() == "+8617180655340"
        user1.destroy()
Example #33
0
def test_get_methods():  # type: () -> None
    user = User()
    user.login("user1_name", "password")

    user.set_username("new_user1")
    assert user.get_username() == "new_user1"

    user.set_mobile_phone_number("18611111111x")
    assert user.get_mobile_phone_number() == "18611111111x"

    user.set_password("new_password")
    assert user._attributes.get("password") == "new_password"

    user.set_email("*****@*****.**")
    assert user.get_email() == "*****@*****.**"
Example #34
0
def login():
    username = request.form['username']
    password = request.form['password']
    user = User()
    try:
        user.login(username, password)
        result = {
            'token': user.get_session_token(),
            'error': 0
        }
    except LeanCloudError as e:
        result = {
            'error': e.error
        }
    return jsonify(result), 200, AccessControl
Example #35
0
def test_get_methods():
    user = User()
    user.login('user1_name', 'password')

    user.set_username('new_user1')
    assert user.get_username() == 'new_user1'

    user.set_mobile_phone_number('18611111111x')
    assert user.get_mobile_phone_number() == '18611111111x'

    user.set_password('new_password')
    assert user._attributes.get('passWord') == 'new_password'

    user.set_email('*****@*****.**')
    assert user.get_email() == '*****@*****.**'
Example #36
0
def test_get_methods():
    user = User()
    user.login('user1_name', 'password')

    user.set_username('new_user1')
    assert user.get_username() == 'new_user1'

    user.set_mobile_phone_number('18611111111x')
    assert user.get_mobile_phone_number() == '18611111111x'

    user.set_password('new_password')
    assert user._attributes.get('password') == 'new_password'

    user.set_email('*****@*****.**')
    assert user.get_email() == '*****@*****.**'
Example #37
0
def login():
    if request.method == 'GET':
        return render_template('users/login.html')
    if request.method == 'POST':
        user = User()
        username = request.form.get('username', '').strip()
        password = request.form.get('password', '').strip()
        if not username or not password:
            flash('用户名和密码不能为空。')
            return redirect(url_for('users.login'))
        try:
            user.login(username, password)
        except LeanCloudError as e:
            flash(e.error)
            return redirect(url_for('users.login'))
        return redirect(url_for('recommends.show'))
Example #38
0
    def post(self):
        username = self.get_argument("username")
        password = self.get_argument("password")
        if "admin" == username:
            try:
                user = User()
                user.login(username, password)
            except leancloud.errors.LeanCloudError as e:
                print(e.code, e.error)
                self.redirect("/admin/login/")

            self.set_secure_cookie("user_id", user.id)
            self.set_secure_cookie("username", username)
            self.redirect("/admin/")
        else:
            self.redirect("/admin/login/")
Example #39
0
def login():
    if request.method == 'POST':
        next_url = request.args.get('next') or '/'
        username = request.form.get('username')
        password = request.form.get('password')
        remember_me = False
        user = User()
        print next_url, username, password
        try:
            user.login(username, password)
            login_user(user, remember=remember_me)
            flash('Logged in successfully')
        except LeanCloudError:
            return redirect('/login')
        return redirect(next_url)
    return render_template('login.html')
Example #40
0
def login():
    if request.method == 'GET':
        return render_template('users/login.html')
    if request.method == 'POST':
        user = User()
        username = request.form.get('username', '').strip()
        password = request.form.get('password', '').strip()
        if (not username or not password) or (not ((username == 'WX') or
                                                   (username == 'DJ') or
                                                   (username == 'ZY') or
                                                   (username == 'GOD'))):
            flash('用户名和密码不能为空,或者你不是公司内部成员。')
            return redirect(url_for('users.login'))
        try:
            user.login(username, password)
        except LeanCloudError as e:
            flash(e.error)
            return redirect(url_for('users.login'))
        return redirect(url_for('todos.show'))
Example #41
0
def test_current_user():
    user = User()
    user.login('user1_name', 'password')
    assert user.is_current
    assert User.get_current().id == user.id
Example #42
0
def test_user_become(): # type: () -> None
    existed_user = User()
    existed_user.login('user1_name', 'password')
    session_token = existed_user.session_token
    user = User.become(session_token)
    assert user.get('username') == existed_user.get('username')
Example #43
0
def test_user_become():
    existed_user = User()
    existed_user.login('user1_name', 'password')
    session_token = existed_user.get_session_token()
    user = User.become(session_token)
    assert user.get('username') == existed_user.get('username')
Example #44
0
def test_update_password():
    user = User()
    user.login('user1_name', 'password')
    user.update_password('password', 'new_password')
    user.login('user1_name', 'new_password')
Example #45
0
def test_current_user():
    user = User()
    user.login('user1_name', 'password')
    assert user.is_current
    assert User.get_current().id == user.id
Example #46
0
def test_update_user():
    user = User()
    user.login('user1_name', 'password')
    user.set('nickname', 'test_name')
    user.save()
Example #47
0
def test_update_password(): # type: () -> None
    user = User()
    user.login('user1_name', 'password')
    user.update_password('password', 'new_password')
    user.login('user1_name', 'new_password')
Example #48
0
def test_update_user():
    user = User()
    user.login('user1_name', 'password')
    user.set('nickname', 'test_name')
    user.save()
Example #49
0
def test_update_password():  # type: () -> None
    user = User()
    user.login('user1_name', 'password')
    user.update_password('password', 'new_password')
    user.login('user1_name', 'new_password')
Example #50
0
def test_user_become():
    existed_user = User()
    existed_user.login('user1_name', 'password')
    session_token = existed_user.get_session_token()
    user = User.become(session_token)
    assert user.get('username') == existed_user.get('username')
Example #51
0
def test_update_password():
    user = User()
    user.login('user1_name', 'password')
    user.update_password('password', 'new_password')
    user.login('user1_name', 'new_password')