Esempio n. 1
0
                                      example='*****@*****.**'),
                  password=fields.String(title='Your password',
                                         required=True,
                                         example='password.Pa55word'),
                  confirm_password=fields.String(title='Confirm your password',
                                                 required=True,
                                                 example='password.Pa55word'),
                  security_question=fields.String(
                      title='Your security question',
                      required=True,
                      example='What is your favourite company?'),
                  security_answer=fields.String(title='Your security answer',
                                                required=True,
                                                example='company'))

user_registration_model = auth_ns.model('user_registration_model', definition)


class Register(Resource):
    @auth_ns.expect(user_registration_model)
    @auth_ns.response(201, 'user created successfully')
    @auth_ns.response(415, 'request data not in json format')
    @auth_ns.response(400, 'bad request')
    def post(self):
        """
        User registration

        1. Email address should be syntactically valid.
        2. Password should have a minimum of 12 characters and a maximum of 80 characters
        3. Password should have no spaces
        4. Password should have at least one number, uppercase and lowercase letter.
Esempio n. 2
0
from flask_restplus import Resource, fields
from flask_restplus.namespace import Namespace

from restplus.api.v1.auth.helpers import extract_auth_data, generate_auth_output
from restplus.models import users_list

auth_ns = Namespace('auth')

login_manager = LoginManager()

user_login_model = auth_ns.model(
    'user_login', {
        'email':
        fields.String(title='Your email address',
                      required=True,
                      example='*****@*****.**'),
        'password':
        fields.String(title='Your email address',
                      required=True,
                      example='password.Pa55word')
    })


@login_manager.user_loader
def load_user(user_id):
    for a_user in users_list:
        # In the session, user_id is stored as a unicode character
        # The chr() converts the int id of the user found to unicode for comparing equality
        if chr(a_user.id) == user_id:
            return a_user
Esempio n. 3
0
from flask import url_for
from flask_login import login_required, current_user
from flask_restplus import Resource, fields
from flask_restplus.namespace import Namespace

from davepostAPI.api.v1.boilerplate import check_id_availability, PayloadExtractionError, extract_from_payload, \
    get_validated_payload, generate_post_output
from davepostAPI.models import users_list, User, posts_list, PostTransactionError

users_ns = Namespace('users')
post_model = users_ns.model(
    'post_model', {
        'title':
        fields.String(title='The title of your post',
                      required=True,
                      example='My Post Title'),
        'body':
        fields.String(title='The body of your post',
                      required=True,
                      example='Something interesting for people to read.')
    })


class SingleUserAllPosts(Resource):
    @users_ns.response(200, "Success")
    @users_ns.response(400, "Post not found. Invalid 'post_id' provided")
    def get(self, user_id: int):
        """
        View all posts from a single user
        """
        this_user = None