コード例 #1
0
def register_action():
    if request.form:
        formData = request.form
        user = UserController(formData['name'], formData['email'],
                              formData['password'])
        result = user.register_action()
        if result[1] is 'success':
            return redirect(url_for('login'))
    return redirect(url_for('register'))
コード例 #2
0
def edit_customer_action():
    if request.form:
        formData = request.form
        user = UserController()
        result = user.edit_customer(formData['id'], formData['name'],
                                    formData['date_birth'], formData['cpf'],
                                    formData['rg'], formData['phone'])
        if result:
            return redirect(url_for('view_customer', id=formData['id']))
コード例 #3
0
def create_customer():
    if request.form:
        formData = request.form
        user = UserController()
        result = user.create_customer(formData['name'], formData['date_birth'],
                                      formData['cpf'], formData['rg'],
                                      formData['phone'])
        if result:
            return redirect(url_for('list_customers'))

    return redirect(url_for('new_customer'))
コード例 #4
0
def login_action():
    formData = request.form

    user = UserController()
    result = user.login_action(formData['email'], formData['password'])
    if result:
        session['logged_in'] = True
        session['user'] = result.name
        session['email'] = result.email
        return redirect(url_for('dashboard'))
    return redirect(url_for('login'))
コード例 #5
0
def dashboard():
    if not session.get('logged_in'):
        return redirect(url_for('login'))
    else:
        customer = CustomerController()
        user = UserController()
        customers = customer.get_all_customers_count()
        users = user.get_all_users_count()
        return render_template('dashboard.html',
                               customers=customers,
                               users=users,
                               user=session['user'])
コード例 #6
0
def new_address_action():
    if request.form:
        formData = request.form
        user = UserController()
        result = user.new_customer_address(formData['street'],
                                           formData['district'],
                                           formData['city'], formData['state'],
                                           formData['country'],
                                           formData['customer_id'])
        if result:
            return redirect(
                url_for('view_customer', id=formData['customer_id']))
コード例 #7
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def ViewUser(id_user):

    user = UserController.find_user(id_user)

    if user:
        return user.json()

    return {'msg': 'User Not Found'}, 404  #not found
コード例 #8
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def DeleteUser(id_user):
    user = UserController.find_user(id_user)

    if user:
        try:
            user.delete_user()
        except:
            traceback.print_exc()
            return {'msg': 'An error ocurred trying to delete user'}, 500

        return {'msg': 'User Deleted'}

    return {'msg': 'User Not Found'}, 404
コード例 #9
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def UserLogin():
    dados = atributos.parse_args()

    user = UserController.find_by_login(dados['login'])

    if user and safe_str_cmp(user.password, dados['password']):
        if user.ativado:
            token_de_acesso = create_access_token(identity=user.id)
            return {'access_token': token_de_acesso}, 200

        return {'msg': 'User not confirmed'}, 400

    return {
        'msg': 'The username or password is incorrect.'
    }, 401  #não autorizado
コード例 #10
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def UserConfirm(id_user):
    user = UserController.find_user(id_user)

    if not user:
        return {"msg": "User id '{}' not found".format(id_user)}, 404

    user.ativado = True
    user.save_user()

    #return {"msg":"User id '{}' confirmed successfully".format(user_id)}, 200
    headers = {'Content-Type': 'text/html'}
    return make_response(
        render_template('user_confirm.html',
                        email=user.email,
                        usuario=user.login), 200, headers)
コード例 #11
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def UpdateUser(id_user):
    dados = atributos.parse_args()

    user = UserController.find_user(id_user)

    if user:
        user.update_user(dados.get('password'))
        try:
            user.save_user()
            #desloga o usuario
            jwt_id = get_raw_jwt()['jti']  #JWT token Identifier
            BLACKLIST.add(jwt_id)
        except:
            traceback.print_exc()
            return {
                'msg': 'An internal error ocurred trying to update hotel.'
            }, 500

        return {
            'msg': 'Password successfully modified. Log in again!'
        }, 200  #ok

    return {'msg': 'User not found.'}, 404  #Internal server error
コード例 #12
0
ファイル: auth.py プロジェクト: lsp-rs/taskboard
import functools
from flask import (Blueprint, flash, g, redirect, render_template, request,
                   session, url_for)
from app.controllers.UserController import UserController
usr_ctrl = UserController()

bp = Blueprint('auth', __name__)


def login_required(view):
    @functools.wraps(view)
    def wrapped_view(**kwargs):
        if not 'login' in session.keys():
            return redirect(url_for('auth.login'))
        return view(**kwargs)

    return wrapped_view


@bp.route('/', methods=('GET', 'POST'))
def login():
    try:
        if 'login' in session.keys():
            return redirect(url_for('taskboard.home'))
        if request.method == 'POST':
            data_login = {
                'email': request.form['email'],
                'password': request.form['password']
            }
            usr_ctrl.signIn(data_login)
            if session['login']:
コード例 #13
0
ファイル: User.py プロジェクト: mac-alves/sk-flask
def UserRegister():

    dados = atributos.parse_args()

    if not dados.get('email') or dados.get('email') is None:
        return {"msg": "The field 'email' cannot be left black"}, 400

    if UserController.find_by_email(dados.get('email')):
        return {
            "msg": "The email '{}' already exists".format(dados.get('email'))
        }, 400

    if (not dados.get('login')) or (dados.get('login') is None):
        return {"msg": "The field 'login' cannot be left blank"}

    if UserController.find_by_login(dados['login']):
        return {"msg": "The login '{}' already exists".format(dados['login'])}

    user = UserController(**dados)
    user.ativado = False

    try:
        user.save_user()
        user.send_confirmation_email()
    except:
        user.delete_user()
        traceback.print_exc()
        return {'msg': 'An internal server error has ocurred'}, 500

    return {'msg': 'User created successfully!'}, 201  # created
コード例 #14
0
# 3rd party modules
from flask import Response

# Internal modules
from app import app
from app.controllers.UserController import UserController
from app.controllers.AuthController import AuthController

controller: UserController = UserController()
auth = AuthController.get_instance()


@app.route('/api/v1/users', methods=['POST'])
def create_user() -> Response:
    return controller.create_user()


@app.route('/api/v1/users/<id>', methods=['GET'])
def find_user(id) -> Response:
    return controller.find_by_id(id)


@app.route('/api/v1/users', methods=['GET'])
@auth.authorize(["ADMIN"])
def find_all_users() -> Response:
    return controller.get_all()


@app.route('/api/v1/users/<id>', methods=['DELETE'])
@auth.authorize(["ADMIN"])
def delete_user(id) -> Response: