Beispiel #1
0
 def test_delete(self):
     self.login_as_admin()   # this will add a user name admin!
     user = add_user('name1', 'pw1', 'normal')
     user_key = user.key
     assert len(get_user(key=user_key)) == 1
     self.app.delete('/api/user/%s/' % (user_key))
     assert len(get_user(key=user_key)) == 0
Beispiel #2
0
    def test_add_user_history(self):
        user = add_user('name1', 'pw1', 'normal')
        add_user_history(user, 'favor', 'f' * 24)
        user = get_user(key=user.key)[0]
        assert len(user.history) == 1
        assert len(user.favor) == 1
        assert len(user.dislike) == 0

        add_user_history(user, 'dislike', 'f' * 24)
        user = get_user(key=user.key)[0]
        assert len(user.history) == 2
        assert len(user.favor) == 0
        assert len(user.dislike) == 1

        add_user_history(user, 'favor', 'f' * 24)
        user = get_user(key=user.key)[0]
        assert len(user.history) == 3
        assert len(user.favor) == 1
        assert len(user.dislike) == 0

        add_user_history(user, 'listened', 'f' * 24)
        user = get_user(key=user.key)[0]
        assert len(user.history) == 4
        assert user.listened == 1

        add_user_history(user, 'shared', 'f' * 24)
        user = get_user(key=user.key)[0]
        assert len(user.history) == 5
        assert len(user.shared) == 1
Beispiel #3
0
 def test_delete_user(self):
     name = 'user_name'
     password = '******'
     level = 'normal'
     user = add_user(name, password, level)
     assert len(get_user()) == 1
     user = get_user()[0]
     delete_user(user)
     assert len(get_user()) == 0
Beispiel #4
0
 def test_add_user(self):
     name = 'user_name'
     password = '******'
     level = 'normal'
     user = add_user(name, password, level)
     assert add_user(name, password, level) is None
     assert len(get_user(key=user.key)) == 1
     user = get_user()[0]
     assert user.name == 'user_name'
     assert user.password == _encrypt('user_name', 'user_password')
     assert check_user_password(user, 'user_password')
     assert user.level == 'normal'
Beispiel #5
0
    def login():
        username = request.json.get('username', None)
        password = request.json.get('password', None)

        user = get_user(username)
        if not user or not check_user_password(password, user.get('password')):
            return jsonify({
                'login': False,
                'reason': 'INVALID_CREDENTIALS'
            }), 401

        company = get_company_by_admin_user(user['_id'])
        if user['type'] == UserType.HIRING_MANAGER \
                and not company.get('enabled', False):
            return jsonify({'login': False, 'reason': 'COMPANY_DISABLED'}), 401

        # Create the tokens we will be sending back to the user
        identity = _create_identity_object(user, company)
        access_token = create_access_token(identity=identity)
        refresh_token = create_refresh_token(identity=identity)

        # Set the JWTs and the CSRF double submit protection cookies
        # in this response
        resp = {
            'accessToken': access_token,
            'refreshToken': refresh_token,
        }
        resp.update(identity)
        # set_access_cookies(resp, access_token)
        # set_refresh_cookies(resp, refresh_token)
        return jsonify(resp), 200
Beispiel #6
0
 def post(self):
     args = UserLoginArgs().args
     user = get_user(name=args['name'])[0]
     if check_user_password(user, args['password']) and check_user_enable(user):
         session['user'] = user.key
         return marshal(user, user_fields)
     return None
    def test_get_user(self):
        created_user = self.create_from_factory(UserFactory)
        self.create_from_factory(UserFactory)

        user = get_user(created_user['_id'])

        self.assertEquals(created_user['_id'], user['_id'])
Beispiel #8
0
 def GET(self):
     name = gc('name')
     if name:
         #return 'test'
         user = get_user(name)
         return st("admin/main.mako", **locals())
     return st("admin/login.mako", **locals())
Beispiel #9
0
 def GET(self, id):
     name = gc('name')
     article = Article.get(id)
     if article and name:
         user = get_user(name)
         return st("admin/edit.mako", **locals())
     return st("404.mako", **locals())
Beispiel #10
0
def get_phone_number_users(rds):
    if not request.data:
        return INVALID_PARAM()
    req = json.loads(request.data)
    resp = []
    contacts = []
    for o in req:
        uid = user.make_uid(o["zone"], o["number"])
        u = user.get_user(rds, uid)
        obj = {}
        obj["zone"] = o["zone"]
        obj["number"] = o["number"]

        if u is None:
            obj["uid"] = 0
        else:
            contact = user.Contact()
            contact.name = o["name"] if o.has_key("name") else ""
            contact.uid = uid
            contacts.append(contact)
            obj["uid"] = uid
            if u.state:
                obj["state"] = u.state
            if u.avatar:
                obj["avatar"] = u.avatar
            if u.up_timestamp:
                obj["up_timestamp"] = u.up_timestamp
        resp.append(obj)
            
    user.set_user_contact_list(rds, request.uid, contacts)
    return make_response(200, resp)
Beispiel #11
0
 def GET(self, id):
     name = gc('name')
     article = Article.get(id)
     if article and name:
         user = get_user(name)
         return st("admin/edit.mako", **locals())
     return st("404.mako", **locals())
Beispiel #12
0
 def get(self):
     user = get_user(key=session['user'])[0]
     args = UserHistoryQueryArgs().args  # use history query args
     if 'start' not in args:
         args['start'] = None
     if 'end' not in args:
         args['end'] = None
     return marshal(get_user_favor(user, args['start'], args['end']), music_fields)
    def test_get_user_no_password(self):
        created_user = self.create_from_factory(UserFactory)
        self.create_from_factory(UserFactory)

        user = get_user(created_user['_id'], exclude_password=True)

        self.assertIsNone(user.get('password'))
        self.assertIsNotNone(user.get('first_name'))
Beispiel #14
0
 def GET(self):
     name = gc('name')
     if name:
         #return 'test'
         user = get_user(name)
         articles = get_user_articles(user.name)
         return st("admin/manage.mako", **locals())
     return st("admin/login.mako", **locals())
Beispiel #15
0
 def post(self):
     args = UserLoginArgs().args
     user = get_user(name=args['name'])[0]
     if check_user_password(user,
                            args['password']) and check_user_enable(user):
         session['user'] = user.key
         return marshal(user, user_fields)
     return None
Beispiel #16
0
 def GET(self):
     name = gc('name')
     if name:
         #return 'test'
         user = get_user(name)
         articles = get_user_articles(user.name)
         return st("admin/manage.mako", **locals())
     return st("admin/login.mako", **locals())
Beispiel #17
0
 def POST(self):
     req = gd()
     name = gc("name")
     if name:
         user = get_user(name)
         ok = add(req.cate, req.title, req.url, req.content, user.name)
         return js(dict(r=True, ok=ok))
     else:
         return js(dict(r=False))
Beispiel #18
0
 def POST(self):
     req = gd()
     name = gc('name')
     if name:
         user = get_user(name)
         ok = add(req.cate, req.title, req.url, req.content, user.name)
         return js(dict(r = True, ok = ok))
     else:
         return js(dict(r = False))
Beispiel #19
0
 def get(self):
     user = get_user(key=session['user'])[0]
     args = UserHistoryQueryArgs().args  # use history query args
     if 'start' not in args:
         args['start'] = None
     if 'end' not in args:
         args['end'] = None
     return marshal(get_user_favor(user, args['start'], args['end']),
                    music_fields)
    def test_create_hidden_hiring_manager(self):
        create_hidden_hiring_manager(username=self.username)
        stored_user = get_user(username=self.username)

        self.assertEquals(stored_user['_id'], self.username)
        self.assertIsNotNone(stored_user['password'], self.username)
        self.assertEquals(stored_user['type'], UserType.HIRING_MANAGER)
        self.assertEquals(stored_user['first_name'], self.username)
        self.assertEquals(stored_user['last_name'], self.username)
        self.assertIsNone(stored_user['title'])
Beispiel #21
0
 def test_update_user(self):
     name = 'user_name'
     password = '******'
     level = 'normal'
     add_user(name, password, level)
     user = get_user()[0]
     update_user(user, password='******', level='disable')
     user = get_user()[0]
     assert user.name == 'user_name'
     assert user.password == _encrypt(user.name, 'new_password')
     assert check_user_password(user, 'new_password')
     assert user.level == 'disable'
     try:
         update_user(user, name='some_name')
     except AttributeError:
         pass
     try:
         update_user(user, level='some_level')
     except AssertionError:
         pass
Beispiel #22
0
 def test_patch(self):
     self.login_as_admin()   # this will add a user name admin!
     user = add_user('name1', 'pw1', 'normal')
     user_key = user.key
     rv = self.app.patch('/api/user/%s/' % (user_key),
                         data={'password': '******',
                               'level': 'admin'})
     rv = json.loads(rv.data)
     assert rv['level'] == 'admin'
     user = get_user(key=user_key)[0]
     assert check_user_password(user, 'new_password')
    def test_set_password(self):
        user = self.create_from_factory(UserFactory)

        new_password = "******"

        update_user_password(user_id=user['_id'], new_password=new_password)

        stored_user = get_user(username=user['_id'])

        self.assertTrue(check_user_password(new_password,
                                            stored_user['password']))
Beispiel #24
0
def login_action():
    form = LoginForm(request.form)

    username = form.username.data
    password = form.password.data

    user = user_model.get_user(username)

    if not check_password(user, password):
        raise AuthorizationException("Неверный пароль")

    login_user(user)
    return redirect(url_for('index_page'))
Beispiel #25
0
def profile_edit_page(username):
    user = user_model.get_user(username)
    form = AboutForm(request.form, obj=user)

    if not can_edit_profile(current_user, user):
        raise AuthorizationException(
            "Вы не можете редактировать этого пользователя.")

    if request.form and form.validate():
        form.populate_obj(user)
        return redirect(url_for('profile.profile_page', username=username))

    return render_template('profile_edit.html', user=user, form=form)
Beispiel #26
0
def get():
    id = request.args.get('id')
    if not (id and ObjectId.is_valid(id)):
        abort(400)

    result = get_user(ObjectId(id))
    if not result:
        return Response(status=404)

    obj = convert_user_from_mongo(result)
    response_data = json.dumps(obj)
    logger.debug('--response_data--' + response_data)
    resp = Response(response=response_data, status=201, content_type='application/json')
    return resp
Beispiel #27
0
def get_user_contact(rds):
    uid = request.uid
    contacts = user.get_user_contact_list(rds, uid)
    resp = []
    for contact in contacts:
        u = user.get_user(rds, contact.uid)
        if u is None:
            continue
        obj = {}
        if u.avatar:
            obj["avatar"] = u.avatar
        obj["uid"] = int(contact.uid)
        obj["name"] = contact.name
        resp.append(obj)
    return json.dumps(resp)
Beispiel #28
0
    def test_update_password(self):
        user_1 = self.create_from_factory(UserFactory)
        new_password = "******"

        self.assertFalse(check_user_password(new_password, user_1['password']))

        url = self.url_for_admin(USER_URL, user_id=user_1['_id'])
        response = self.post_json(url, data={'password': new_password})

        self.assertEqual(200, response.status_code)

        stored_user = get_user(user_1['_id'])

        self.assertTrue(
            check_user_password(new_password, stored_user['password']))
Beispiel #29
0
def login():
    if request.method == "GET":
        if "logged_in" in session:
            return redirect(url_for("user.feed"))
        return render_template("auth/login.html")

    print("login")
    usermail = request.form["email"]
    password = request.form["password"]
    user = get_user(usermail, password)
    print(user)
    if user is not None:
        session["logged_in"] = user
        return redirect(url_for("user.feed"))
    else:
        return render_template(
            "auth/login.html",
            msg="Wrong password or email address try again!")
Beispiel #30
0
def access_token():
    if not request.data:
        return INVALID_PARAM()

    obj = json.loads(request.data)
    c1 = obj["code"]
    number = obj["number"]
    zone = obj["zone"]
    if is_test_number(number):
        pass
    else:
        c2, timestamp, _ = code.get_verify_code(g.rds, zone, number)
        if c1 != c2:
            return INVALID_CODE()

    uid = user.make_uid(zone, number)

    access_token = gobelieve.login_gobelieve(uid, "")
        
    if not access_token:
        return CAN_NOT_GET_TOKEN()

    u0 = user.get_user(g.rds, uid)
    u = user.User()
    u.uid = uid
    if u0 is None:
        u.state = "Hey!"
    else:
        u.state = u0.state

    user.save_user(g.rds, u)

    tok = {
        'expires_in': 3600,
        'token_type': 'Bearer',
        "access_token":access_token,
        "refresh_token":random_token_generator(),
        'uid':int(uid)
    }

    Token.save_access_token(g.rds, access_token, uid, 3600)
    Token.save_refresh_token(g.rds, tok['refresh_token'], uid)
    
    return make_response(200, tok)
    def test_sign_in_company(self):

        input_data = load_example_model('sign_in_company')

        url = self.url_for(COMPANIES_URL)
        response = self.post_json(url, input_data)

        self.assertEqual(200, response.status_code)

        result_company = loads(response.data)
        stored_company_id = result_company['admin_user_ids'][0]

        self.assertEqual(input_data['company_name'], result_company['name'])
        self.assertEqual(input_data['company_description'],
                         result_company['description'])

        stored_hm = get_user(stored_company_id)
        self.assertIsNotNone(stored_hm)
        self.assertEqual(stored_hm['type'], UserType.HIRING_MANAGER)

        self.assertEqual(input_data['hm_email'],
                         result_company['contacts']['email'])
Beispiel #32
0
 def GET(self):
     name = gc('name')
     if name:
         user = get_user(name)
         return st("admin/add.mako", **locals())
     return st("admin/login.mako", **locals())
Beispiel #33
0
def character_create_page(username):
    return create_edit_character_page(character=None,
                                      user=user_model.get_user(username))
Beispiel #34
0
 def post(self):
     user = get_user(key=session['user'])[0]
     args = UserHistoryPostArgs().args
     add_user_history(user, args['op'], args['key'])
Beispiel #35
0
 def patch(self, key):
     args = UserPatchArgs().args
     user = get_user(key=key)[0]
     update_user(user, **args)
     user = get_user(key=key)[0]
     return user
Beispiel #36
0
 def GET(self):
     name = gc("name")
     if name:
         user = get_user(name)
         return st("admin/add.mako", **locals())
     return st("admin/login.mako", **locals())
Beispiel #37
0
 def post(self):
     user = get_user(key=session['user'])[0]
     args = UserHistoryPostArgs().args
     add_user_history(user, args['op'], args['key'])
Beispiel #38
0
def get_current_user():
    try:
        return get_user(key=session['user'])[0]
    except:
        return None
Beispiel #39
0
def get_current_user():
    try:
        return get_user(key=session['user'])[0]
    except:
        return None
Beispiel #40
0
 def get(self):
     args = UserQueryArgs().args
     if args == {}:
         return marshal(get_user_status(), user_status_fields)
     users = get_user(**args)
     return marshal(users, user_fields)
Beispiel #41
0
def UserKey(key):
    try:
        assert get_user(key=key)[0]
    except:
        raise ValueError("Invalid User Key")
    return key
Beispiel #42
0
def profile_page(username):
    user = user_model.get_user(username)
    return render_template('profile.html',
                           user=user,
                           characters=user.characters.order_by(
                               lambda ch: (desc(ch.status), desc(ch.id))))
Beispiel #43
0
 def get(self):
     try:
         user = get_user(key=session['user'])[0]
         return marshal(user, user_fields)
     except:
         return None
Beispiel #44
0
 def delete(self, key):
     user = get_user(key=key)[0]
     delete_user(user)
Beispiel #45
0
 def get(self):
     args = UserQueryArgs().args
     if args == {}:
         return marshal(get_user_status(), user_status_fields)
     users = get_user(**args)
     return marshal(users, user_fields)
Beispiel #46
0
 def get(self):
     try:
         user = get_user(key=session['user'])[0]
         return marshal(user, user_fields)
     except:
         return None