예제 #1
0
파일: core.py 프로젝트: hifiveszu/hifive
def change_password():
    form = g.form

    user = User.objects.filter(id=current_user.id).first()
    if user is None:
        return fail_jsonify(code=codes.NOT_USER)

    if not user.check_password(form.old_password.data):
        return fail_jsonify(code=codes.WRONG_PASSWORD)

    user.change_password(form.new_password.data)
    user.save()
    return ok_jsonify({})
예제 #2
0
파일: core.py 프로젝트: hifiveszu/hifive
def login():
    form = g.form
    condition = Q(user_name=trim(form.user_name.data))
    user = User.objects.filter(condition).first()
    if user is None:
        return fail_jsonify(code=codes.NOT_USER)

    if not user.check_password(trim(form.password.data)):
        return fail_jsonify(code=codes.WRONG_PASSWORD)

    if not (user.is_authenticated() and user.is_active()):
        return fail_jsonify(code=codes.UNAUTHENTICATED)

    remember_me = True if form.remember_me.data else False
    login_user(user, remember=remember_me)
    User.objects(id=user.id).update_one(last_login=datetime.utcnow())

    res = jsonify(code=0)
    res.set_cookie('token', get_token())
    return res
예제 #3
0
파일: core.py 프로젝트: hifiveszu/hifive
def register():
    form = g.form
    condition = Q(user_name=form.user_name.data)
    if User.objects.filter(condition).first():
        return fail_jsonify(code=codes.USER_EXISTED)

    obj = dict(
        user_name=form.user_name.data,
        password=form.password.data,
        email=form.email.data,
        phone=form.phone.data,
        first_name=form.first_name.data,
        last_name=form.last_name.data,
        full_name=form.full_name.data,
    )

    user = User.objects.create(**obj)
    user.change_password(form.password.data)
    user.save()

    return ok_jsonify(data=dict(user=user))
예제 #4
0
파일: core.py 프로젝트: hifiveszu/hifive
def user_info():
    user_info = User.objects.filter(id=current_user.id).first()
    if user_info is None:
        return fail_jsonify(code=codes.NOT_USER)

    return ok_jsonify(data=dict(user_info=user_info))