Ejemplo n.º 1
0
 def check_user_logged_in(self):
     if self.request.cookies.get('User'):
         user_id = self.read_cookies('User')
         if user_id:
             from modals.users import Users
             print Users.get_by_id(int(user_id))
             return Users.get_by_id(int(user_id))
         else:
             return None
Ejemplo n.º 2
0
 def check_user_logged_in(self):
     if self.request.cookies.get( 'User' ):
         user_id = self.read_cookies( 'User' )
         if user_id:
             from modals.users import Users
             print Users.get_by_id( int( user_id ) )
             return Users.get_by_id( int( user_id ) )
         else:
             return None
Ejemplo n.º 3
0
    def post(self):
        email = self.request.get('email')
        name = self.request.get('name')
        password = self.request.get('password')
        status = 200
        print name, email, password

        if name and email and password:

            email_validation_pattern = "(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
            if re.match(email_validation_pattern, email):

                user = Users.add_new_user(name, email, password)
                if user['created']:
                    pass
                    html = self.jinja_environment.get_template(
                        'commons/register_modal_sucess.html').render()
                    json_response = {'html': html}
                    self.send_email(
                        to=email,
                        user_id=user['user_id'],
                        confirmation_code=user['confirmation_code'])
                else:
                    status = 400
                    json_response = user
            else:
                status = 400
                json_response = {
                    'created': False,
                    'title': "this email is not valid",
                    'message': "please enter a valid email"
                }

        else:
            status = 400
            json_response = {}

            if not email:
                json_response.update({
                    'title':
                    'you have not sent us an email',
                    'message':
                    'Please send us a valid email address,thanks!'
                })
            if not password:
                json_response.update({
                    'title': 'Please type in a password',
                    'message': 'Please a send us ur password'
                })
            if not name:
                json_response.update({
                    'title':
                    'The Name field is required',
                    'message':
                    'Please fill in your name in order to continue'
                })

        self.json_response(status_code=status, **json_response)
Ejemplo n.º 4
0
    def post(self):
        email = self.request.get( 'email' )
        name = self.request.get( 'name' )
        password = self.request.get( 'password' )
        status = 200
        print name, email, password

        if name and email and password:

            email_validation_pattern = "(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
            if re.match( email_validation_pattern, email ):

                user = Users.add_new_user( name, email, password )
                if user['created']:
                    pass
                    html = self.jinja_environment.get_template( 'commons/register_modal_sucess.html').render()
                    json_response = {
                        'html': html
                    }
                    self.send_email( to=email, user_id=user['user_id'], confirmation_code=user['confirmation_code'] )
                else:
                    status = 400
                    json_response = user
            else:
                status = 400
                json_response = {
                    'created': False,
                    'title': "this email is not valid",
                    'message': "please enter a valid email"
                }

        else:
            status = 400
            json_response = {}

            if not email:
                json_response.update(
                    {
                        'title': 'you have not sent us an email',
                        'message': 'Please send us a valid email address,thanks!'
                    }
                )
            if not password:
                json_response.update(
                    {
                        'title': 'Please type in a password',
                        'message': 'Please a send us ur password'
                    }
                )
            if not name:
                json_response.update(
                    {
                        'title': 'The Name field is required',
                        'message': 'Please fill in your name in order to continue'
                    }
                )

        self.json_response( status_code=status, **json_response )
Ejemplo n.º 5
0
    def post(self):
        email = self.request.get( 'email' )
        password = self.request.get( 'password' )
        user_id = Users.check_password( email, password )
        print email
        if user_id:
            print user_id
            self.send_cookie( name='User', value=user_id )
            self.redirect( '/account' )

        else:
            self.redirect( '/login' )