Exemplo n.º 1
0
    def post(self, userID):

        """
            上传头像
            :return:
            """
        from werkzeug.utils import secure_filename
        from faker import Faker

        f = Faker()
        file = request.files.get('file')
        if not file:
            return jsonify(myResponse(ResponseCode.ERROR, None, ResponseError.NO_FIlE))
        if not userID:
            return jsonify(myResponse(ResponseCode.ERROR, None, cantEmpty("userID")))
        user = User.get(userID)
        fileName = secure_filename(file.filename)
        filePath = getAvatarPath(f.pystr() + '_' + fileName)
        user.avatar = filePath

        try:
            file.save(filePath)
            user.save()
            return jsonify(myResponse(ResponseCode.SUCCESS, user.id, ResponseError.OK))
        except Exception as e:
            log.error(e)
            return jsonify(myResponse(ResponseCode.ERROR, None, ResponseCode.ERROR_TRY_AGAIN))
Exemplo n.º 2
0
def account_settings():
    """Account Settings Page.

    allow admin to change profile.

    Methods:
        GET and POST

    Args:
        GET:
            none

        POST:
            username: string
            pass1   : password
            pass2   : password twice for validate
            signature: user profile signature
            email   : for get reply email notification

    Returns:
        GET:
            user object
        POST:
            none
    """
    user = UserModel.objects(name=current_user.name).first()
    if request.method == 'POST':
        username = request.form['username']
        pass1 = request.form['pass1']
        pass2 = request.form['pass2']
        signature = request.form['signature']
        email = request.form['email']
        avatar = request.form['avatar']

        if pass1 and pass2 and pass1 == pass2:
            user.password = generate_password_hash(password=pass1)

        if username:
            user.name = username

        if signature:
            user.signature = signature

        if email:
            user.email = email

        if avatar:
            user.avatar = avatar

        user.save()

        if pass1 or username:
            logout_user()
            flash(u"请重新登陆")
            return redirect(url_for("admin.index"))

        return redirect(url_for("admin.account_settings"))
    else:
        return render_template('admin/account/settings.html', user=user)
Exemplo n.º 3
0
def verify_password_or_token(username_or_token, password):
    """登录状态校验"""
    user = User.verify_token(token=username_or_token)
    if not user:
        user = User.query.filter(User.account == username_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
Exemplo n.º 4
0
def register_user():
    response = {
        'msg': 'success'
    }
    try:
        name = flask.request.get_json()['name']
        gender = flask.request.get_json()['gender']
        age = flask.request.get_json()['age']

        user = User()
        user.name = name
        user.gender = gender
        user.age = age

        session.add(user)
        session.commit()
    except Exception as e:
        traceback.print_exc()
        session.rollback()
        response['msg'] = str(e)
    return flask.jsonify(response)
Exemplo n.º 5
0
    def post(self) -> jsonify:
        """
        注册 post请求
        :return: jsonify
        """
        parse = MyParse()
        parse.add(name="account", required=True)
        parse.add(name="name", required=True)
        parse.add(name="password", required=True)
        parse.add(name="departmentId", type=int, required=False)
        parse.add(name="admin", type=bool, required=False, default=False)
        parse.add(name="gender", type=bool, required=False, default=True)
        parse.add(name="email", required=False)
        parse.add(name="phone", required=False)

        departmentId = parse.parse_args().get("departmentId")
        account = parse.parse_args().get("account")
        name = parse.parse_args().get("name")
        password = parse.parse_args().get("password")
        admin = parse.parse_args().get("admin")
        gender = parse.parse_args().get('gender')
        email = parse.parse_args().get("email")
        phone = parse.parse_args().get("phone")

        if departmentId:
            # departmentId验证
            Department.get(departmentId, 'departmentId')

        # name 验证
        User.verify_account(account.lower())
        u = User(account=account, name=name, password=password, gender=gender, department=departmentId, admin=admin,
                 email=email, phone=phone)
        u.save()

        return jsonify(myResponse(ResponseCode.SUCCESS, u.id, ResponseError.OK))
Exemplo n.º 6
0
def userInfo():
    if request.method == 'POST':
        user = User()
        user.name = request.form.get("name")
        session['name'] = user.name;
        user.pwd = request.form.get("password")
        result = database.checkUser(user.name, user.pwd)
        if result:
            user.pNumber = result[0][3]
            user.age = result[0][2]
            user.sex = "male"
            if not result[0][5]:
                user.sex = "femail"
            return render_template("userInformation.html", user=user)
        return redirect(url_for('login'))
Exemplo n.º 7
0
Arquivo: user.py Projeto: xzh1223/WB
def register(request):
    ctx = {}
    if request.method == 'POST':
        username = request.POST.get("username", "")
        mobile = request.POST.get("mobile", "")
        password = request.POST.get("password", "")
        email = request.POST.get("email", "")
        if username == "":
            ctx['code'] = 1
            ctx['msg'] = "username is no null"
        elif password == "":
            ctx['code'] = 1
            ctx['msg'] = "password is no null"
        elif mobile == "":
            ctx['code'] = 1
            ctx['msg'] = "mobile is no null"
        elif len(mobile) != 11:
            ctx['code'] = 1
            ctx['msg'] = "mobile's length is must achieve 11"
        elif email == "":
            ctx['code'] = 1
            ctx['msg'] = "email is no null"
        else:
            user_list = User.objects.filter(username=username, mobile=mobile)
            if len(user_list) > 0:
                ctx['code'] = 1
                ctx['msg'] = "current user is exist"
            else:
                user = User(username=username,
                            mobile=mobile,
                            password=password,
                            email=email)
                user.save()
                ctx['code'] = 0
                ctx['msg'] = "register success"

    return return_json(ctx)
Exemplo n.º 8
0
def build():
    user = User(name='admin')
    user.password = generate_password_hash(password='******')
    user.save()
    print "Default Admin add Success!"
    execute(deploy)
Exemplo n.º 9
0
 def get(self, userID):
     user = User.get(userID)
     avatar = user.avatar
     with open(avatar, "rb") as f:
         avatar = f.read()
     return Response(avatar, mimetype="image/jpeg")
Exemplo n.º 10
0
 def add_user(self, user: UserObj):
     user_data = User(username=user.get_username(),
                      password_hash=user.set_password_hash())
     session.add(user_data)
     session.commit()
     return True