Ejemplo n.º 1
0
def signup():
    """用户注册"""
    un = request.get_json().get("username")
    email = request.get_json().get("email")
    password = request.get_json().get("password")

    if User.query.filter_by(username=un).first() is not None:
        return jsonify({}), 401
    if User.query.filter_by(email=email).first() is not None:
        return jsonify({}), 402
    if un is None or email is None or password is None:
        return jsonify({}), 403

    user = User(
        username=un,
        email=email,
        password=base64.b64encode(password),
        avatar_url="http://7xrvvt.com1.z0.glb.clouddn.com/shakedog.gif",
    )

    db.session.add(user)
    db.session.commit()

    return jsonify({
        "created": user.id,
    }), 200
Ejemplo n.º 2
0
def adduser():
    """
    add users
    -------------------------------
    User: write & comment
    Moderator: write & comment & moderate_comments
    Administrator: full permissions
    """
    from getpass import getpass

    email = raw_input('email: ')
    username = raw_input('username: '******'group: ')
    role_id = input('user:3, admin:2, moderator:1: ')
    password = getpass('password: '******'confirm: ')
    if password == confirm:
        user = User(email=email,
                    username=username,
                    password=password,
                    group=group,
                    left=False,
                    role_id=role_id)
        db.session.add(user)
        db.session.commit()
        return "user %s add in database !" % username
    else:
        return "password not confirmed !"
        sys.exit(0)
Ejemplo n.º 3
0
def edit_profile():
    """编辑用户信息"""
    token = request.headers.get('token')
    un = request.args.get('username')

    user = User.query.filter_by(username=un).first()

    if not user or not user.id == User.verify_auth_token(token):
        return jsonify({}), 403

    user.avatar_url = request.get_json().get("avatar_url")
    user.birthday = request.get_json().get("birthday")
    user.flickr = request.get_json().get("flickr")
    user.github = request.get_json().get("github")
    user.group = request.get_json().get("group")
    user.hometown = request.get_json().get("hometown")
    user.info = request.get_json().get("info")
    user.personal_blog = request.get_json().get("personal_blog")
    user.timejoin = request.get_json().get("timejoin")
    user.timeleft = request.get_json().get("timeleft")
    user.weibo = request.get_json().get("weibo")
    user.zhihu = request.get_json().get("zhihu")

    db.session.add(user)
    db.session.commit()

    return jsonify({}), 201
Ejemplo n.º 4
0
def rter():
    """用户注册接口"""
    if current_user.role_id == 2:
        form = RterForm()
        if form.validate_on_submit():
            u = User(username=form.username.data, password=form.password.data)
            db.session.add(u)
            db.session.commit()
        return render_template('r.html', form=form)
    else:
        return redirect(url_for('books.home'))
Ejemplo n.º 5
0
def adduser(email, username):
    """添加用户"""
    from getpass import getpass
    password = getpass('password')
    confirm = getpass('confirm')
    if password == confirm:
        user = User(email=email, username=username, password=password)
        db.session.add(user)
        db.session.commit()
        return "user %s add in database !" % username
    else:
        return "password not confirmed !"
        sys.exit(0)
Ejemplo n.º 6
0
def new_user():
    """
    注册一个用户
    """
    name = request.args.get('username')
    pw = request.args.get('password')
    em = request.args.get('email')
    user = User.query.filter_by(username=name).first()
    user = User(
        username=name,
        email=em,
        password=pw,
        avatar_url='http://7xrvvt.com1.z0.glb.clouddn.com/shakedog.gif',
        role_id=3)
    db.session.add(user)
    db.session.commit()
    return jsonify({'new user': user.id}), 201
Ejemplo n.º 7
0
    def signup(self):
        """用户注册"""

        ID = 0
        if User.query.filter_by(username=self.un).first() is not None:
            return jsonify({}), 401
        if self.un is None or self.password is None:
            return jsonify({}), 403

        user = User(
            username=self.un,
            password=base64.b64encode(self.password),
            avatar_url="http://7xrvvt.com1.z0.glb.clouddn.com/shakedog.gif",
            role_id=3)

        db.session.add(user)
        db.session.commit()
        ID = user.id

        return ID, 200
Ejemplo n.º 8
0
 def decorated(*args, **kwargs):
     token = request.headers.get('token')
     if User.verify_auth_token(token) is not None:
         g.current_user = User.verify_auth_token(token)
         return f(*args, **kwargs)
     return jsonify({}), 401