Пример #1
0
 def post(self):
     email, password = auth_logic_api.payload.get(
         'email'), auth_logic_api.payload.get('password')
     if email is None or password is None:
         return jsonify({
             'result': False,
             'error': 'Email or password is not provided'
         })
     existing_user = db_user_service.find_user_by_email(email)
     if existing_user is None:
         return jsonify({
             'result':
             False,
             'error':
             'User does not exist or never being confirmed.'
         })
     else:
         if existing_user.verify_hash(password):
             login_response = jwt_api.login_create_tokens(existing_user.id)
             return make_response(login_response, 200)
         else:
             return jsonify({
                 'result': False,
                 'error': 'Email or password is wrong.'
             })
Пример #2
0
    def post(self):
        username, email, password = auth_logic_api.payload.get('username'), auth_logic_api.payload.get('email'), \
                                    auth_logic_api.payload.get('password')
        if username is None or email is None or password is None:
            return jsonify({
                'result':
                False,
                'error':
                'Username, email, or password is not provided'
            })

        existing_user = db_user_service.find_user_by_email(email)
        if existing_user is not None:
            return jsonify({'result': False, 'error': 'User already exists.'})
        # New user has been created but not saved
        new_user = db_user_service.create_user(username, email, password)
        if new_user is not None:
            # 1. Save new user - to get id for the token generation
            save_result = new_user.save()

            if save_result:
                # 2. Generate confirmation token
                token = new_user.generate_verification_token()

                # 3. Generate email bodies and send confirmation link asynchronously
                send_verification_email(new_user,
                                        token,
                                        action='confirm',
                                        template_name='confirmation_template',
                                        subject='Confirm your registration')

                # 4. Inform frontend to redirect to the confirmatiuon page
                confirm_email_page_url = '/auth/finishregister/' + str(
                    new_user.id)
                return jsonify({
                    'result': True,
                    'redirect': confirm_email_page_url
                })
            return jsonify({
                'result':
                False,
                'error':
                'Something went wrong when saving a new user. Please try to register again.'
            })
        else:
            return {
                'result':
                False,
                'error':
                'Something went wrong, could not register a user, please try again.'
            }
Пример #3
0
    def post(self):
        email, password = auth_logic_api.payload.get(
            'email'), auth_logic_api.payload.get('password')
        if email is None or password is None:
            return jsonify({
                'result': False,
                'error': 'Email or password is not provided'
            })
        existing_user = db_user_service.find_user_by_email(email)
        if existing_user is None:
            return jsonify({
                'result':
                False,
                'error':
                'User does not exist or never being confirmed.'
            })
        else:
            if existing_user.confirmed == False:
                # Inform frontend to redirect to the confirmatiuon page
                token = existing_user.generate_verification_token()
                send_verification_email(existing_user,
                                        token,
                                        action='confirm',
                                        template_name='confirmation_template',
                                        subject='Confirm your registration')
                confirm_email_page_url = '/auth/finishregister/' + str(
                    existing_user.id)
                return jsonify({
                    'result': False,
                    'error':
                    'Please confirm your email. You will be redirected to the confirmation page in 3 secods.',
                    'redirect': confirm_email_page_url,
                    'redirectDelay': 3
                })

            if existing_user.verify_hash(password):
                login_user(existing_user,
                           auth_logic_api.payload.get('remember'))
                login_response = jwt_api.login_create_tokens(existing_user.id)
                return make_response(login_response, 200)
            else:
                return jsonify({
                    'result': False,
                    'error': 'Email or password is wrong.'
                })
Пример #4
0
 def post(self):
     email = auth_logic_api.payload.get('email')
     if email is None:
         return jsonify({
             'result': False,
             'error': 'Please provide a non-empty email.'
         })
     # Note: for the security purpose we don't say if user exists or not and send this message no matter
     # if user was found in our database or not.
     message = 'We send the link at the provided email. If you don\'t have it please check your email and enter it again. Another reason you don\'t have email from us is you did\'t registered with our service.'
     existing_user = db_user_service.find_user_by_email(email)
     if existing_user is None:
         return jsonify({'result': True, 'message': message})
     else:
         token = existing_user.generate_verification_token(key='forgot',
                                                           expiration=1800)
         send_verification_email(existing_user,
                                 token,
                                 action='resetpassword',
                                 template_name='reset_password_template',
                                 subject='Request for password reset')
         return jsonify({'result': True, 'message': message})