Ejemplo n.º 1
0
    def get(self):
        """
        Determine whether the user correctly spelled the key word during
        her wakeup call.
        
        For instance, 'W-A-L-R-U-S' is correct.
        """
        digits = self.request.get('Digits')
        the_number = self.request.get('To')

        try:
            the_user = User.all().filter('phone_number =',
                                         the_number).fetch(1)[0]
        except IndexError:
            return 'FAIL'

        stop = (digits == chars_to_digits('stop'))
        correct = (digits == chars_to_digits(TODAYS_KEYWORD['word']))

        call_record = Call(user=the_user, correct_response=correct)
        call_record.put()

        if correct:
            res = YOU_SPELLED_THE_WALRUS
        else:
            if stop:
                the_user.delete()
                res = UNSUBSCRIBE
            else:
                res = THATS_NOT_HOW_YOU_SPELL_WALRUS % {
                    'keyword': TODAYS_KEYWORD['word'],
                    'domain': WALRUS_DOMAIN
                }
        return self.return_XML(res)
Ejemplo n.º 2
0
 def test_chg_pwd(self):
     self.assertIsNone(
         User.register(None, '*****@*****.**', 'abc', 'abc', 'first', 'last'),
         'About to test changing of passwords'
     )
     user = User.all().filter('email =', '*****@*****.**').get()
     self.assertIsNotNone(user)
     self.assertIsNotNone(
         user.chgpwd('wrong', 'good', 'good'),
         'Wrong original password'
     )
     self.assertIsNotNone(
         user.chgpwd('abc', 'blah', 'different'),
         'Passwords differ'
     )
     self.assertIsNone(
         User.authenticate(None, '*****@*****.**', 'abc'),
         'Password should not have changed'
     )
     self.assertIsNone(
         user.chgpwd('abc', 'newpwd', 'newpwd'),
         'Valid change of password'
     )
     self.assertIsNone(
         User.authenticate(None, '*****@*****.**', 'newpwd'),
         'Password should have changed'
     )
     self.assertIsNotNone(user.chgpwd(None, None, None))
Ejemplo n.º 3
0
    def get(self):
        """
        Determine whether the user correctly spelled the key word during
        her wakeup call.
        
        For instance, 'W-A-L-R-U-S' is correct.
        """
        digits = self.request.get('Digits')
        the_number = self.request.get('To')

        try:
            the_user = User.all().filter('phone_number =', the_number).fetch(1)[0]
        except IndexError:
            return 'FAIL'
        
        stop = (digits == chars_to_digits('stop'))
        correct = (digits == chars_to_digits(TODAYS_KEYWORD['word']))
        
        call_record = Call(user=the_user, correct_response=correct)
        call_record.put()
        
        if correct:
            res = YOU_SPELLED_THE_WALRUS
        else:
            if stop:
                the_user.delete()
                res = UNSUBSCRIBE
            else:
                res = THATS_NOT_HOW_YOU_SPELL_WALRUS % {
                    'keyword': TODAYS_KEYWORD['word'],
                    'domain': WALRUS_DOMAIN
                }
        return self.return_XML(res)
Ejemplo n.º 4
0
 def get(self, project_id):
     project = get_project(project_id)
     users = User.all()
     context = {
         'project': project,
         'users': users,
     }
     self.render_to_response('projects/edit.html', context)
Ejemplo n.º 5
0
 def clean_nickname(self):
     data = self.cleaned_data.get('nickname')
     q = User.all()
     q.filter("nickname =", data)
     result = q.get()
     if result is not None:
         raise forms.ValidationError("The Nickename Already Exist!")
     return data
Ejemplo n.º 6
0
 def clean_email(self):
     data = self.cleaned_data.get('email')
     q = User.all()
     q.filter("email =", data)
     result = q.get()
     if result is not None:
         raise forms.ValidationError("The Email Already Exist!")
     return data
Ejemplo n.º 7
0
 def test_formatting(self):
     self.assertIsNone(
         User.register(None, '*****@*****.**', 'abc', 'abc', 'first', 'last'),
         'About to test automatic capitalisation'
     )
     user = User.all().filter('email =', '*****@*****.**').get()
     self.assertIsNotNone(user)
     self.assertEqual(user.fname, 'First')
     self.assertEqual(user.lname, 'Last')
Ejemplo n.º 8
0
    def test_register_login(self):
        self.assertIsNotNone(
            User.authenticate(None, '*****@*****.**', 'correcthorse'),
            'Try to login with an email that doesn\'t exist'
        )
        self.assertIsNone(
            User.register(None, '*****@*****.**', 'correcthorse', 'correcthorse', 'matt', 'stark'),
            'Register an account'
        )
        self.assertIsNotNone(
            User.register(None, '*****@*****.**', 'pwd', 'pwd', 'first', 'last'),
            'Attempt to register an account when the name is already taken'
        )
        self.assertIsNone(
            User.authenticate(None, '*****@*****.**', 'correcthorse'),
            'Login with valid username and password'
        )
        self.assertIsNotNone(
            User.authenticate(None, '*****@*****.**', 'valid'),
            'Attempt to login with wrong password'
        )
        self.assertIsNotNone(User.authenticate(None, None, None))

        self.assertIsNotNone(
            User.do_reset(None, 'newpwd', 'newpwd'),
            'Don\'t let them reset the password if reset_code is None'
        )

        user_qry = User.all().filter('email =', '*****@*****.**').get
        self.assertIsNotNone(User.setup_reset(None))

        self.assertIsNone(user_qry().reset_code)

        self.assertIsNone(User.setup_reset('*****@*****.**'))
        self.assertIsNotNone(user_qry().reset_code)

        self.assertIsNotNone(
            User.do_reset('abc', 'newpwd', 'newpwd'),
            'Invalid code'
        )
        self.assertIsNotNone(
            User.do_reset(user_qry().reset_code, 'newpwd1', 'newpwd2'),
            'Different passwords'
        )
        self.assertIsNone(
            User.do_reset(user_qry().reset_code, 'newpwd', 'newpwd'),
            'Reset the password'
        )
        self.assertIsNotNone(
            User.do_reset(user_qry().reset_code, 'newpwd', 'newpwd'),
            'Ensure you can\'t reset the password more than once with the same code'
        )
        self.assertIsNone(
            User.authenticate(None, '*****@*****.**', 'newpwd'),
            'Login with valid username and password'
        )
Ejemplo n.º 9
0
async def add_process_time_header(request: Request, call_next):
    async for obj in User.all():
        print(obj.email)
    email = request.headers.get('x-auth', '').strip()
    user = await User.get_or_none(email=email).prefetch_related('roles')
    if not user:
        raise HTTPException(status_code=401)

    request.headers['x-auth'] = user
    return await call_next(request)
Ejemplo n.º 10
0
    def get(self, phone_number):
        """
        Show a calendar summary of the user's responses to wakeup calls
        
        !! This will explode in 2012
        """
        user = User.all().filter('phone_number =', "+%s" % phone_number).get()
        if user is None:
            return self.http404()
        history = {}
        calls = Call.all().filter('user ='******'day':
                    d,
                    'correct_response':
                    False
                } for d in cal.itermonthdays2(2011, call.created.month)]

            for day_history in month_history:
                if day_history['day'][0] == call.created.day:
                    day_history['correct_response'] = True
                    break

        # If there is nothing in the history, add the current month to
        # ensure that at least one month is rendered
        if len(history) == 0:
            now = datetime.datetime.now()
            history[now.strftime("%B")] = [{
                'day': d,
                'correct_response': False
            } for d in cal.itermonthdays2(2011, now.month)]

        context = {'user': user, 'history': history}
        path = os.path.join(TEMPLATE_DIR, 'results.html')
        self.response.out.write(template.render(path, context))
Ejemplo n.º 11
0
 def get(self, phone_number):
     """
     Show a calendar summary of the user's responses to wakeup calls
     
     !! This will explode in 2012
     """
     user = User.all().filter('phone_number =', "+%s" % phone_number).get()
     if user is None:
         return self.http404()
     history = {}
     calls = Call.all().filter('user ='******'day': d, 'correct_response': False} 
                 for d in cal.itermonthdays2(2011, call.created.month)
             ]
             
         for day_history in month_history:
             if day_history['day'][0] == call.created.day:
                 day_history['correct_response'] = True
                 break
                 
     # If there is nothing in the history, add the current month to
     # ensure that at least one month is rendered
     if len(history) == 0:
         now = datetime.datetime.now()
         history[now.strftime("%B")] = [
             {'day': d, 'correct_response': False} 
             for d in cal.itermonthdays2(2011, now.month)
         ]
             
     context = {'user': user, 'history': history}
     path = os.path.join(TEMPLATE_DIR, 'results.html')
     self.response.out.write(template.render(path, context))
Ejemplo n.º 12
0
    def get(self):
        """
        Check if any calls are scheduled to be made this minute, 
        and if so, tell twilio to make them
        """
        now = datetime.datetime.now()

        now_time = now.time()
        lookback_time = (now - datetime.timedelta(minutes=5)).time()
        all_users = User.all().filter('wakeup_time <',
                                      now_time).filter('wakeup_time >',
                                                       lookback_time)

        # exclude users for which their timezone puts them in a weekend
        all_users = filter(lambda u: not u.is_local_weekend(), all_users)

        # exclude users for which a call has recently been made
        all_users = filter(lambda u: not u.recently_called(), all_users)

        # for each number, tell twilio to make a call
        question_url = "%s/twilio/question" % WALRUS_DOMAIN
        [u.call(question_url) for u in all_users]

        self.response.out.write(str(now_time))
Ejemplo n.º 13
0
    def get(self):
        """
        Check if any calls are scheduled to be made this minute, 
        and if so, tell twilio to make them
        """
        now = datetime.datetime.now()
        
        now_time = now.time()
        lookback_time = (now - datetime.timedelta(minutes=5)).time()
        all_users = User.all().filter('wakeup_time <', now_time).filter('wakeup_time >', lookback_time)
        
        # exclude users for which their timezone puts them in a weekend
        all_users = filter(lambda u: not u.is_local_weekend(), all_users)
        
        # exclude users for which a call has recently been made
        all_users = filter(lambda u: not u.recently_called(), all_users)

        # for each number, tell twilio to make a call
        question_url = "%s/twilio/question" % WALRUS_DOMAIN
        [u.call(question_url) for u in all_users]
        
        self.response.out.write(str(now_time))

        
Ejemplo n.º 14
0
 def get(self):
     users = User.all()
     context = {
         'users': users,
     }
     self.render_to_response('projects/create.html', context)