Exemple #1
0
    def post(self):

        data = RegisterUser.get_register_args()

        user = UserModel.find_by_email(data['email'])
        if user:
            return {'msg': 'User with given email already exists!'}, 400

        user = UserModel.find_by_username(data['user_name'])
        if user:
            return {'msg': 'User with given username already exists!'}, 400

        user = UserModel(**data)
        user.save_to_db()

        send_activation_email(user)

        return {'msg': 'Please check mail to activate the account'}, 201
Exemple #2
0
    def post(self):

        data = User.get_create_args()

        user = UserModel.find_by_email(data['email'])
        if user:
            return {'msg': 'User with given email already exists!'}, 400

        user = UserModel.find_by_username(data['user_name'])
        if user:
            return {'msg': 'User with given username already exists!'}, 400

        user = UserModel(**data)
        user.save_to_db()

        if not current_app.config['TESTING']:
            send_activation_email(user)

        return {'msg': 'Please check mail to activate the account'}, 201
Exemple #3
0
    def post(self):
        start_time = time.time()

        data = LoginUser.get_login_args()

        user = UserModel.find_by_username(data['user_name'])

        if not user:
            return {'error': 'No user with given username'}, 400

        if user.status == 0:
            return {'error': 'You must activate your account'}, 400

        if not user.check_password(data['password']):
            return {'error': 'Password is incorrect'}, 400

        token = user.get_token()

        log = ActivityModel(user.id, url_for('loginuser'),
                            (time.time() - start_time))
        log.save_to_db()

        return {'token': token.decode('utf-8')}