Beispiel #1
0
class UserPasswordHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        if request.method in ('POST'):
            self.__reqparse.add_argument('password', type=str, required=True)
        elif request.method in ('PATCH'):
            self.__reqparse.add_argument('old_password',
                                         type=str,
                                         required=True)
            self.__reqparse.add_argument('new_password',
                                         type=str,
                                         required=True)

        self.__args = self.__reqparse.parse_args()

    @login_required
    def patch(self):
        self.__userdata = current_user.info
        self.__args['acct_code'] = self.__userdata['acct_code']
        self.__args['login_uuid'] = self.__userdata['uuid']
        user_password = UserPassword(self.__args)

        return user_password.update()

    @login_required
    def post(self, login_uuid):
        self.__userdata = current_user.info
        self.__args['acct_code'] = self.__userdata['acct_code']
        self.__args['login_uuid'] = login_uuid
        user_password = UserPassword(self.__args)

        return user_password.save()
Beispiel #2
0
class UserMeHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        if request.method in ('GET'):
            self.__reqparse.add_argument('get_account_deletion_status',
                                         type=bool)

        self.__args = self.__reqparse.parse_args()

    @login_required
    def get(self):
        self.__userdata = current_user.info
        person_data = {'id': self.__userdata['person']['id']}
        person = Person(person_data).get()
        retval = {
            'me': {
                'person': person['person'][0],
                'login_name': self.__userdata['login_name']
            }
        }
        if self.__args['get_account_deletion_status']:
            if app.config['ACTIVATE_ACCOUNT_DELETION'] == 'TRUE':
                retval['me']['activate_account_deletion'] = True
            else:
                retval['me']['activate_account_deletion'] = False

        return retval
Beispiel #3
0
class AuthenticateHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__reqparse.add_argument('username', type=str, required=True)
        self.__reqparse.add_argument('password', type=str, required=True)
        self.__reqparse.add_argument('remember_me', type=bool)
        self.__reqparse.add_argument('X-Forwarded-For',
                                     type=str,
                                     dest='ip',
                                     location='headers')
        self.__reqparse.add_argument('User-Agent',
                                     type=str,
                                     dest='ua',
                                     location='headers')
        self.__args = self.__reqparse.parse_args()

    def post(self):
        retval = {}
        if self.__args.get('ip', None) is None:
            self.__args['ip'] = request.remote_addr

        device = user_agent_parser.Parse(self.__args['ua'])
        self.__args['device'] = device['os']['family']
        user = User.authenticate(**self.__args)
        if user.is_authenticated:
            retval['status'] = 'SUCCESS'
            retval['token'] = user.get_request_token()
        else:
            retval['status'] = 'FAILED'
            retval['message'] = 'Invalid login credentials'

        return retval
Beispiel #4
0
class PasswordResetHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__reqparse.add_argument('accountcode', type=str, required=True)
        self.__reqparse.add_argument('username', type=str, required=True)
        self.__reqparse.add_argument('email', type=str)
        self.__reqparse.add_argument('X-Forwarded-For', type=str, dest='ip')
        self.__reqparse.add_argument('User-Agent',
                                     type=str,
                                     dest='ua',
                                     location='headers')

    def post(self):
        self.__args = self.__reqparse.parse_args()
        retval = {
            'status':
            'SUCCESS',
            'message':
            'We have sent an email to the account holder if user exists.'
        }
        if self.__args.get('ip', None) is None:
            self.__args['ip'] = request.remote_addr

        device = user_agent_parser.Parse(self.__args['ua'])
        self.__args['device'] = device['os']['family']
        user = User(**self.__args)
        if user.is_exist:
            reset_token = user.generate_reset_token()

        return retval

    def get(self):
        self.__reqparse.add_argument('reset_token', type=str, required=True)
        self.__args = self.__reqparse.parse_args()
        retval = {}
        user = User.validate_token(**self.__args)
        if user.is_exist:
            retval['status'] = 'SUCCESS'
        else:
            retval['status'] = 'FAILED'

        return retval

    def patch(self):
        self.__reqparse.add_argument('reset_token', type=str, required=True)
        self.__reqparse.add_argument('password', type=str, required=True)
        self.__args = self.__reqparse.parse_args()
        retval = {}
        user = User.validate_token(**self.__args)
        if user.is_exist:
            user.update_password(self.__args['password'])
            user.remove_token()
            retval['status'] = 'SUCCESS'
        else:
            retval['status'] = 'FAILED'

        return retval
Beispiel #5
0
class ActivateHandler(Resource):
    decorators = [limiter.limit("3/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__reqparse.add_argument('email', type=str, required=True)
        self.__reqparse.add_argument('code', type=str, required=True)
        self.__reqparse.add_argument('X-Forwarded-For', type=str, dest='ip')
        self.__reqparse.add_argument('User-Agent',
                                     type=str,
                                     dest='ua',
                                     location='headers')
        self.__args = self.__reqparse.parse_args()

    def post(self):
        data = {
            'login_name': self.__args['email'],
            'token': self.__args['code']
        }
        activate = Activate(data)
        retval = activate.activate_login()
        if retval['status'] == 'SUCCESS':
            if self.__args.get('ip', None) is None:
                self.__args['ip'] = request.remote_addr

            device = user_agent_parser.Parse(self.__args['ua'])
            self.__args['device'] = device['os']['family']
            login_data = {'login_name': self.__args['email']}
            users = Users(login_data)
            login_retval = users.get()
            if login_retval['status'] == 'SUCCESS':
                login_info = {}
                for data in login_retval['data']:
                    login_info['accountcode'] = app.config['GROUP_CODE']
                    login_info['auth_provider'] = 'login'
                    login_info['auth_token'] = ''
                    login_info['username'] = data['login_name']
                    login_info['login_name'] = data['login_name']
                    login_info['ua'] = self.__args['ua']
                    login_info['user_agent'] = self.__args['ua']
                    login_info['client_ipaddress'] = self.__args['ip']
                    login_info['ip'] = self.__args['ip']
                    login_info['device'] = self.__args['device']
                    login_info['uuid'] = data['login_uuid']
                    login_info['account_activated'] = data['is_activated']
                    login_info['last_login'] = data['last_login_date']
                    login_info['password_reset_count'] = data[
                        'password_reset_count']
                    login_info['login_params'] = {
                        'acct_code': app.config['GROUP_CODE'],
                        'user_type': 'WEB'
                    }
                    user = User.autologin(**login_info)
                    if user.is_authenticated:
                        login_user(user)

        return retval
Beispiel #6
0
class EmailHandler(Resource):
    decorators = [limiter.limit("2/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__args = self.__reqparse.parse_args()
        self.__args['group_code'] = app.config['GROUP_CODE']

    def post(self):
        email = Email(self.__args)
        retval = email.save()

        return retval
Beispiel #7
0
class LoginHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__reqparse.add_argument('username', type=str, required=True)
        self.__reqparse.add_argument('password', type=str, required=True)
        self.__reqparse.add_argument('X-Forwarded-For', type=str, dest='ip')
        self.__reqparse.add_argument('User-Agent',
                                     type=str,
                                     dest='ua',
                                     location='headers')
        self.__args = self.__reqparse.parse_args()

    def post(self):
        retval = {}
        login_params = {
            'acct_code': app.config['GROUP_CODE'],
            'user_type': 'WEB'
        }
        self.__args['accountcode'] = app.config['GROUP_CODE']
        self.__args['company_code'] = 'PONOS'
        self.__args['user_type'] = 'WEB'
        self.__args['login_params'] = login_params
        if self.__args.get('ip', None) is None:
            self.__args['ip'] = request.remote_addr

        device = user_agent_parser.Parse(self.__args['ua'])
        self.__args['device'] = device['os']['family']
        user = User.authenticate(**self.__args)
        if user.is_authenticated:
            login_user(user)
            userdata = current_user.info
            args = {'requested_by': userdata['login_name']}
            get_request = Request(args).get()
            for req in get_request['request']:
                if req['status'] != 'FAILED':
                    current_user.remove()
                    logout_user()
                    return {
                        'status': 'FAILED',
                        'message': 'Invalid login credentials'
                    }

            retval['status'] = 'SUCCESS'
        else:
            retval['status'] = 'FAILED'
            retval['message'] = 'Invalid login credentials'

        return retval
Beispiel #8
0
class EmailVerifyHandler(Resource):
    decorators = [limiter.limit("2/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__args = self.__reqparse.parse_args()

    @login_required
    def post(self):
        self.__userdata = current_user.info
        token_data = {
            'token_type': 'LOGIN_ACTIVATION',
            'login_uuid': self.__userdata['uuid']
        }
        get_token = Token(token_data)
        retval_token = get_token.get()
        token_param = retval_token['token'][0]['token']
        client_url = url_for('index', login_name=None, _external=True, _scheme='https')
        activation_url = '{}activate?code={}&email={}'.format(client_url, token_param, self.__userdata['person']['email'])
        data = {
            'client_code': app.config['CLIENT_CODE'],
            'name': self.__userdata['person']['firstname'],
            'link': activation_url,
            'img_link': client_url + 'static/assets/images/{}/email-logo.png'.format(app.config['CLIENT_CODE'].lower())
        }
        email_template = render_template('email/email-sign-up.html', data=data)
        email_data = {
            'body': '{} Recruitment Email Verification'.format(app.config['CLIENT_CODE']),
            'body_html': email_template,
            'recipient': self.__userdata['person']['email'],
            'sender': app.config['NOREPLY_EMAIL'],
            'subject': '{} Recruitment Email Verification'.format(app.config['CLIENT_CODE']),
            'acct_code': app.config['GROUP_CODE']
        }
        email = Email(email_data)
        email.save()

        return {
            'status': 'SUCCESS',
            'email': self.__userdata['person']['email']
        }
class RequestHandler(Resource):
    decorators = [limiter.limit("2/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__args = self.__reqparse.parse_args()

    @login_required
    def post(self):
        self.__userdata = current_user.info
        self.__args['group_code'] = self.__userdata['group_code']
        self.__args['created_by'] = self.__userdata['login_name']
        self.__args['requested_by'] = self.__userdata['login_name']
        self.__args['request_type'] = "PURGE"
        self.__args['request_subtype'] = "PERSON"
        self.__args['params'] = {'person_id': self.__userdata['person']['id']}

        send_request = RequestAction(self.__args)
        retval = send_request.save()

        return retval
Beispiel #10
0
class MeHandler(Resource):
    decorators = [limiter.limit("5/minute")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__args = self.__reqparse.parse_args()

    @login_required
    def get(self):
        self.__userdata = current_user.info
        self.__args['id'] = self.__userdata['uuid']
        self.__args['acct_code'] = self.__userdata['acct_code']
        users = Users(self.__args)
        retval = users.get()
        if retval['status'] == 'SUCCESS':
            login_info = []
            for data in retval['data']:
                login_info.append({'is_activated': data['is_activated']})

            retval['data'] = login_info

        return retval
class ForgotPasswordHandler(Resource):
    decorators = [limiter.limit("2/days")]

    def __init__(self):
        self.__reqparse = reqparse.RequestParser()
        self.__reqparse.add_argument('email', type=str, required=True)
        self.__args = self.__reqparse.parse_args()

    def post(self):
        recipient_email = self.__args['email']
        self.__args['login_name'] = recipient_email
        self.__args['acct_code'] = app.config['GROUP_CODE']
        forgotpassword = Users(self.__args)
        res = forgotpassword.get()
        retval_login = res
        if retval_login is None:
            return {
                'status': 'FAILED',
                'message': 'Internal Server Error.'
            }

        if 'status' not in retval_login or retval_login['status'] != 'SUCCESS':
            return {
                'status': 'FAILED',
                'message': 'Invalid Email Address or Email Address Not Found.'
            }

        person_uuid = retval_login['data'][0]['person_uuid']
        login_uuid = retval_login['data'][0]['login_uuid']
        person_data = {'person_uuid': person_uuid}
        person = UserPerson(person_data)
        res = person.get()
        retval_person = res
        if res is None:
            return {
                'status': 'FAILED',
                'message': 'Invalid Email Address or Email Address Not Found.'
            }

        if retval_person['status'] != 'SUCCESS':
            return {
                'status': 'FAILED',
                'message': 'Invalid Email Address or Email Address Not Found.'
            }

        person_firstname_param = retval_person['person'][0]['firstname']
        password_param = ''.join(random.choice(string.digits) for _ in range(7))
        password_data = {
            'password': password_param,
            'login_user': recipient_email,
            'login_uuid': login_uuid,
            'acct_code': app.config['GROUP_CODE']
        }
        updatepassword = UserPassword(password_data)
        res = updatepassword.save()
        if res is None:
            return {
                'status': 'FAILED',
                'message': 'Password Reset Failed. Please try again later.'
            }

        client_url = url_for('index', login_name=None, _external=True, _scheme='https')
        email_template = render_template(
            'email/email-forgot-password.html',
            client_code=app.config['CLIENT_CODE'],
            fname=person_firstname_param,
            password=password_param,
            img_link=client_url + 'static/assets/images/{}/email-logo.png'.format(app.config['CLIENT_CODE'].lower())
        )
        email_data = {
            'body': '{} Recruitment Forgot Password'.format(app.config['CLIENT_CODE']),
            'body_html': email_template,
            'recipient': recipient_email,
            'sender': app.config['NOREPLY_EMAIL'],
            'subject': '{} Recruitment Forgot Password'.format(app.config['CLIENT_CODE']),
            'acct_code': app.config['GROUP_CODE']
        }
        email = Email(email_data)
        email_retval = email.send()
        if email_retval['status'] != 'SUCCESS':
            return {
                'status': 'FAILED',
                'message': 'Email sending failed. Please try again later.'
            }

        return email_retval