Ejemplo n.º 1
0
def tambah_user():
    '''Menambah user'''
    form = UserForm()
    if form.validate_on_submit():
        username = request.values.get('username')
        password = request.values.get('password')
        password2 = request.values.get('password2')

        # check if username is available
        if User.query.filter_by(username=username).first():
            flash('Username tidak tersedia !', 'danger')
            return render_template('kejadian/tambah_user.html', form=form, user=current_user)

        # check if password2 is the same as password
        if password != password2:
            flash('Verifikasi Password gagal !', 'danger')
            return render_template('kejadian/tambah_user.html', form=form, user=current_user)

        # save new user data
        new_user = User(
            username=username
        )
        # hash password as md5
        new_user.set_password(password)

        db.session.add(new_user)
        db.session.flush()
        db.session.commit()

        flash('Tambah User berhasil !', 'success')
        return redirect(url_for('admin.users'))

    return render_template('kejadian/tambah_user.html', form=form, user=current_user)
Ejemplo n.º 2
0
def register():
    if session.get('username'):
        return redirect(url_for('index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user_id = User.objects.count()
        user_id += 1

        email = form.email.data
        password = form.password.data
        first_name = form.first_name.data
        last_name = form.last_name.data

        user = User(user_id=user_id,
                    email=email,
                    first_name=first_name,
                    last_name=last_name)

        user.set_password(password)
        user.save()
        flash("You are successfully registered", "success")
        return redirect(url_for('index'))

    return render_template("register.html",
                           title="Register",
                           form=form,
                           register=True)
Ejemplo n.º 3
0
 def post(self):
     data = api.payload
     user = User(user_id=data['user_id'],
                 email=data['email'],
                 first_name=data['first_name'],
                 last_name=data['last_name'])
     user.set_password(data['password'])
     # user.save()
     return jsonify(User.objects(user_id=data['user_id']))