def get(self, token, userid):
     user = db_user_service.get_user_by_id(userid)
     if user:
         if not user.confirmed:
             confirmation_result = user.confirm(token)
             if confirmation_result:
                 user.save()
             else:
                 # The token probably expired, so send a new confirmation email
                 token = user.generate_confirmation_token()
                 send_confirmation_email(user, token)
                 return jsonify({
                     'result':
                     False,
                     'redirect':
                     '/auth/finishregister/{0}'.format(user.id),
                     'redirectDelay':
                     3,
                     'error':
                     'Sorry but your token probably expired. We have sent you a new confirmation email - please check your email box and try again.'
                 })
         # User is confirmed, but we have to logout to make sure that THIS exact user will login then.
         return jsonify({'result': True})
     else:
         return jsonify({
             'result':
             False,
             'error':
             'Sorry but user not found. Please login or register again.'
         })
Пример #2
0
    def post(self, folder_name, generate_flag):
        current_user_id = get_current_user_id()
        current_user = db_user_service.get_user_by_id(current_user_id)
        uploaded_urls = []

        if current_user:
            for key in request.files:
                uploaded_file = request.files.get(key)
                bucket_name = get_config_var('AWS_BUCKET_NAME')
                upload_result = aws_s3_service.upload_file(
                    uploaded_file, bucket_name, folder_name, generate_flag)
                if upload_result.get('result') == True:
                    # Use this code to screen the actual address
                    #    public_file_url = '/pic/{0}/{1}'.format(folder_name, upload_result.get('file_name'))
                    uploaded_urls.append(upload_result.get('file_url'))
                else:
                    return jsonify({
                        'result': False,
                        'error': 'Could not upload files...'
                    })
            return jsonify({
                'result': True,
                'file_urls': uploaded_urls
                #'file_name': upload_result.get('file_name')
            })
        return jsonify({'result': False, 'error': 'Cannot find user.'})
Пример #3
0
 def post(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         try:
             password = password_api.payload.get('password')
             new_password = password_api.payload.get('new_password')
             if current_user.verify_hash(password):
                 current_user.set_password(new_password)
                 current_user.save()
             else:
                 return jsonify({
                     'result': False,
                     'error': 'You are not authorized to change the password.'
                 })
         except Exception as ex:
             # to-do: log exception, for not just print it
             print('ERROR while saving new password')
             print(ex)
             return jsonify({
                 'result': False,
                 'error': 'Can not save a new password. Please refresh the page and try again.'
             })
         return jsonify({
             'result': True
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })
Пример #4
0
 def post(self):
     userid, token, password = auth_logic_api.payload.get('userid'),\
                                 auth_logic_api.payload.get('token'),\
                                 auth_logic_api.payload.get('password')
     user = db_user_service.get_user_by_id(userid)
     if user:
         verification_result = user.verify(token, key='forgot')
         if verification_result:
             user.set_password(password)
             user.save()
             return jsonify({
                 'result': True,
                 'redirect': '/auth/login',
                 'redirectDelay': 3
             })
         else:
             return jsonify({
                 'result':
                 False,
                 'error':
                 'Your token probably expired. Please obtain it again on the login page.'
             })
     else:
         return jsonify({
             'result':
             False,
             'error':
             'Your token probably expired. Please obtain it again on the login page.'
         })
Пример #5
0
 def get(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         return jsonify({
             'result': True,
             'username': current_user.username,
             'email': current_user.email
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })
Пример #6
0
    def delete(self, folder_name):
        current_user_id = get_current_user_id()
        current_user = db_user_service.get_user_by_id(current_user_id)
        bucket_name = get_config_var('AWS_BUCKET_NAME')
        if current_user:
            # Add additional checking preventing abuse deletion
            delete_result = aws_s3_service.delete_file(
                bucket_name, folder_name, uploader_api.payload.get('url'))
            return jsonify({
                'result': delete_result.get('result'),
                'error': delete_result.get('error')
            })

        return jsonify({'result': False, 'error': 'Cannot find user.'})
Пример #7
0
 def get(self, token, userid):
     user = db_user_service.get_user_by_id(userid)
     if user:
         if not user.confirmed:
             user.confirm(token)
             user.save()
         # User is confirmed, but we have to logout to make sure that THIS exact user will login then.
         return jsonify({'result': True})
     else:
         return jsonify({
             'result':
             False,
             'error':
             'Sorry but user not found. Please login or register again.'
         })
Пример #8
0
 def get(self, userid):
     user = db_user_service.get_user_by_id(userid)
     if user:
         token = user.generate_confirmation_token()
         send_confirmation_email(user, token)
         confirm_email_page_url = '/auth/finishregister/' + str(user.id)
         return jsonify({
             'result': True,
             'redirect': confirm_email_page_url
         })
     else:
         return jsonify({
             'result':
             False,
             'error':
             'Sorry but user not found. Please login or register again.'
         })
Пример #9
0
 def post(self):
     current_user_id = get_current_user_id()
     current_user = db_user_service.get_user_by_id(current_user_id)
     if current_user:
         try:
             current_user.username = profile_api.payload.get('username')
             current_user.save()
         except Exception as ex:
             # to-do: log exception, for not just print it
             print('ERROR while saving profile')
             print(ex)
             return jsonify({
                 'result': False,
                 'error': 'Can not save user.'
             })
         return jsonify({
             'result': True
         })
     return jsonify({
         'result': False,
         'error': 'Cannot find user.'
     })
Пример #10
0
 def get(self, userid):
     user = db_user_service.get_user_by_id(userid)
     if user:
         token = user.generate_verification_token()
         send_verification_email(user,
                                 token,
                                 action='confirm',
                                 template_name='confirmation_template',
                                 subject='Confirm your registration')
         return jsonify({
             'result':
             True,
             'redirect':
             '/auth/finishregister/{0}'.format(user.id)
         })
     else:
         return jsonify({
             'result':
             False,
             'error':
             'Sorry but user not found. Please login or register again.'
         })