コード例 #1
0
def register_user():
    username = request.values.get("username", None)
    password = request.values.get("password", None)
    #log.debug(username)
    if username is None or password is None:
        return jsonify({
            "status": -3,
            "msg": "username or password error"
        }), 400
    if RegisterUser.verify_username(username) == False:
        return jsonify({"status": -3, "msg": "username already exists"})
    user_info = {"username": username, "password": password}
    log.debug(user_info)
    if RegisterUser.register(user_info):
        user = User(RegisterUser.get_id(username))
        return jsonify({
            "username": username,
            "msg": "Registered Successfully",
            "status": 0
        })
    return jsonify({
        "username": username,
        "msg": "Registration failed",
        "status": -2
    })
コード例 #2
0
def verify_password(username, password):
    log.debug({"username": username, "password": password})
    if RegisterUser.verify_username(username) == False:
        user = User(RegisterUser.get_id(username))
        if user.verify_password(password):
            g.user = user
            return True
    return False
コード例 #3
0
ファイル: views.py プロジェクト: shawyue/blog
def verify_email():
    email = request.form["email"]
    log.debug(email)
    if (RegisterUser.verify_email(email)):
        return jsonify({"result": 1})
    else:
        return jsonify({"result": 0})
コード例 #4
0
ファイル: views.py プロジェクト: shawyue/blog
def verify_username():
    log.debug(request.form)
    username = request.form["username"]
    if (RegisterUser.verify_username(username)):
        return jsonify({"result": 1})
    else:
        return jsonify({"result": 0})
コード例 #5
0
ファイル: views.py プロジェクト: shawyue/blog
def signup():
    username = request.form.get("username", None)
    password = request.form.get("firstPassword", None)
    email = request.form.get("signupEmail", None)
    captcha = request.form.get("captcha", None)
    user_info = {
        "username": username,
        "password": password,
        "email": email,
        "captcha": captcha
    }
    captcha_obj = Captcha()
    if (captcha_obj.verify_captcha(email, captcha)):
        RegisterUser.register(user_info)
        return redirect(request.args.get('next') or url_for("main.home"))
    else:
        return jsonify({"result": 0})
コード例 #6
0
ファイル: views.py プロジェクト: shawyue/blog
def signin():
    log.debug(request.form)
    input_email = request.form.get("inputEmail", None)
    input_password = request.form.get("inputPassword", None)
    remember_me = request.form.get("remember_me", "0")
    if remember_me == "1":
        remember_me = True
    else:
        remember_me = False
    log.debug(RegisterUser.verify_email(input_email))
    if (RegisterUser.verify_email(input_email) is False):
        user = User(RegisterUser.get_id(input_email))

    if user.verify_password(input_password):
        login_user(user, remember=remember_me)
        return redirect(request.args.get("next") or url_for("main.home"))
    return jsonify({"result": 0})
コード例 #7
0
ファイル: views.py プロジェクト: shawyue/blog
def save_password():
    token = request.values.get("key", None)
    password = request.values.get("password", None)
    try:
        json_data = User.parse_token(token)
    except Exception as e:
        log.error(str(e))
        return jsonify({"result": 0})
    email = json_data["email"]
    user_id = RegisterUser.get_id(email)
    user = User(user_id)
    user.password = password
    url = "/auth/sign"
    return jsonify({"result": 1, "url": url})
コード例 #8
0
from flask_restplus import Resource, Namespace, reqparse, fields
from app.models import RegisterUser


register_user_api = Namespace('users', __name__)
reg_users = RegisterUser()
user_register = register_user_api.model('Register', {'name': fields.String,
                                        'types': fields.String, 'age': fields.Integer})


class RegUsers(Resource):
    """User Registration"""
    @staticmethod
    @register_user_api.expect(user_register)
    def post():
        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, help='Rate cannot be converted',
                            location=['json'])
        parser.add_argument('types', type=str, help='Rate cannot be converted',
                            location=['json'])
        parser.add_argument('age', type=int, help='Rate cannot be converted',
                            location=['json'])
        args = parser.parse_args()
        res = reg_users.post_a_user(name=args['name'], types=args['types'], age=args['age'])
        return res


register_user_api.add_resource(RegUsers, '/register', endpoint='register')
コード例 #9
0
ファイル: manage.py プロジェクト: shawyue/restful-api
def admin(username, password):
    "create administrator"
    from app.models import RegisterUser
    
    re = RegisterUser.register_admin(username, password)
    print(re)