def post(self, entity_id):

        existing_user = User.query(User.email == self.json.get('email').lower()).get()

        if existing_user:
            raise ResponseException('Error: {} already exists.'.format(self.json.get('email').lower()), no_error=True)

        if self.json['role'] == 'client':
            self.json['profile_pending'] = True

        if self.json['role'] == 'coach':
            self.json['approved'] = True

        model = CRUDService.do_post(self, entity_id, return_model=True)
        self.session['user'] = model

        self.resp = model.to_json()

        if model.role is Role.coach:
            add_task(
                '/admin/channel/users',
                'POST',
                payload=self.resp
            )
            self.send_approve_email()

        self.format_resp()
    def get(self):

        users = User.query().fetch(FETCH_LIMIT)
        for user in users:
            user.profile_pending = False

        ndb.put_multi(users)
        self.resp = {'ADMINS': 'NOTIFIED'}

        self.format_resp()
Ejemplo n.º 3
0
    def get(self, entity_id):

        if entity_id:
            self.resp = self.id_get()
        else:
            profile_pending = False
            if self.request.get('pending'):
                profile_pending = True

            users = User.query(User.profile_pending == profile_pending).order(-User.created).fetch(FETCH_LIMIT)
            self.resp = self.json_list(users)

        self.format_resp()
    def post(self, service):

        if service == 'password':
            email = self.json.get('email')
            user = User.query(User.email == email).get()
            if not user:
                raise ResponseException(PROP_NOT_FOUND.format('User', email), no_error=True)

            MailHandler.send_mail(
                email,
                'Password Reset'.format(user.name),
                '{}/password-reset.html'.format(user.locale),
                {
                    'user': user.to_json(),
                    'reset': '{}#/password-reset/{}'.format(self.proto_host, user.key.urlsafe()),
                },
                bcc=self.config.notify
            )

            self.resp = {}
            self.format_resp()
    def post(self, user_id):

        lang_map = {
            'en': {
                'account': 'Account Not Found',
                'pass': '******',
                'approved': 'User has not been approved',
                'disabled': 'User has been disabled'
            },
            'es-mx': {
                'account': 'Account Not Found',
                'pass': '******',
                'approved': 'User has not been approved',
                'disabled': 'User has been disabled'
            },
            'pt-br': {
                'account': 'Account Not Found',
                'pass': '******',
                'approved': 'User has not been approved',
                'disabled': 'User has been disabled'
            }
        }

        locale = self.json.get('locale')

        map = lang_map[locale]

        user = User.query(User.email == self.json['email']).get()
        if not user:
            msg = map['account']
            raise ResponseException(msg, no_error=True)

        if user.profile_pending and user.role == Role.client:
            if not bcrypt.hashpw(self.json['password'], user.password) == user.password:

                msg = map['pass']
                raise ResponseException(msg, no_error=True)

            self.login(user)
            self.resp = {'redirect': '/app#/profile/create'}
            return self.format_resp()


        if not user.approved:
            msg = map['approved']
            raise ResponseException(msg, no_error=True)

        if not user.status:
            msg = map['disabled']
            raise ResponseException(msg, no_error=True)

        if not bcrypt.hashpw(self.json['password'], user.password) == user.password:
            msg = map['pass']
            raise ResponseException(msg, no_error=True)

        client_role_string = self.json.get('role', None)
        if client_role_string:
            client_role = Role.lookup_by_name(client_role_string)

        if not user.profile:
            user.profile = Profile()

        self.login(user)
        self.resp = user.to_json()
        self.format_resp()