Exemple #1
0
def parse_user():
    user = User()
    user.name = request.json.get('name')
    user.age = request.json.get('age')
    user.sex = request.json.get('sex')

    return user
Exemple #2
0
def Register():
    if request.method == "POST":
        # Ensure username was submitted
        if not request.form.get("username"):
            flash('must have username', 'error')
            return redirect(request.url)
        # Ensure password was submitted
        elif not request.form.get("password"):
            flash('must have password', 'error')
            return redirect(request.url)
        elif not request.form.get("confirmation"):
            flash('must have Confirmation', 'error')
            return redirect(request.url)
        elif request.form.get("confirmation") != request.form.get("password"):
            flash('pass dan confirm harus sama', 'error')
            return redirect(request.url)
        usernameuser = request.form.get("username")
        passworduser = request.form.get("password")

        checkres = User.query.filter(User.username == usernameuser).all()

        if len(checkres) > 0:
            flash('username telah terdaftar', 'error')
            return redirect(request.url)
        else:
            users = User(username=usernameuser,
                         password=generate_password_hash(passworduser))
            db.session.add(users)
            db.session.commit()
            res = User.query.filter(User.username == usernameuser).all()
            session["user_id"] = res[0].id
            return redirect('/')
    return render_template('register.html')
Exemple #3
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('uname')
     parser.add_argument('uadd')
     parser.add_argument('uconnum')
     parser.add_argument('uemail')
     parser.add_argument('upass')
     parser.add_argument('admin')
     args = parser.parse_args()
     #us1 = User()
     user = User()
     user.uname=args['uname']
     user.uadd=args['uadd']
     user.uconnum=args['uconnum']
     user.uemail=args['uemail']
     user.encrypt_set_password(args['upass'])
     #user.admin=str(args['admin'])
     user.save()
     return "Success"
Exemple #4
0
def signup():
    form = UserCreateForm()
    if request.method == 'POST' and form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if not user:
            user = User(username=form.username.data,
                        password=generate_password_hash(form.password1.data),
                        email=form.email.data)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('main.root'))
        else:
            flash('이미 존재하는 사용자입니다.')
    return render_template('auth/signup.html', form=form)
Exemple #5
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('uname')
     parser.add_argument('upass')
     args = parser.parse_args()
     usr = User.objects(uname=args['uname']).first()
     #one=User.objects(uname=args['uname'],upass=).count()
     if usr and usr.verify_password(str(args['upass'])):
         #usrobj = User.objects.get(uname=args['uname'])
         if usr.admin :
             return {"Admin": args['uname']}
         else:
             return {'Normal User': args['uname']}
     else:
         return "Sorry"
Exemple #6
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        email = request.form['email']
        password = request.form['password']
        username = request.form['username']
        user = User.query.filter_by(username=username).first()
        email_user = User.query.filter_by(email=email).first()

        if user or email_user:
            flash('用户名或者邮箱重复')
            return redirect('/register')
        model = User(email=email, username=username, password=password)
        db.session.add(model)
        db.session.commit()
        flash('注册成功,现在可以进行登录了')
        return redirect('/login')
Exemple #7
0
 def delete(self):
     parser = reqparse.RequestParser()
     parser.add_argument('us_id')
     args = parser.parse_args()
     User.objects(id=str(args['us_id'])).delete()
     return "Delete Success"