Beispiel #1
0
 def test_create_duplicate_users(self):
     email = "*****@*****.**"
     password = hashlib.md5("random-password").hexdigest()
     bob1 = store.create_user(store.ROLE_EDITOR, email, password, "Bob1")
     self.assertFalse(bob1 is None)
     func = lambda: store.create_user(store.ROLE_CONTRIBUTOR, email, password, "Bob2")
     self.assertRaises(ValidationError, func)
     self.assertRaises(ValidationError, func)
     # get by email, should be only one: Bob1
     us = store.User.all().filter("email =", email).fetch(100)
     self.assertEquals(1, len(us))
     u = store.get_user_by_email(email)
     self.assertEquals(store.ROLE_EDITOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals("Bob1", u.nicename)
Beispiel #2
0
def do_google_signin(**kw):
    ctx = kw['context']
    # get google user:
    gu = users.get_current_user()
    if gu is None:
        logging.error('Google account info is not found. Exit g_signin...')
        raise ApplicationError('Cannot find user information')
    ctx.delete_cookie(cookie.AUTO_SIGNIN_COOKIE)
    email = gu.email().lower()
    nicename = gu.nickname()
    # check if user exist:
    user = store.get_user_by_email(email)
    if user is None:
        # auto-create new user:
        role = store.ROLE_SUBSCRIBER
        if users.is_current_user_admin():
            role = store.ROLE_ADMINISTRATOR
        user = store.create_user(role, email, '', nicename)
    elif users.is_current_user_admin() and user.role!=store.ROLE_ADMINISTRATOR:
        user.role = store.ROLE_ADMINISTRATOR
        user.put()
    ctx.set_cookie(cookie.IS_FROM_GOOGLE_COOKIE, 'yes', 31536000)
    redirect = ctx.get_argument('redirect', '/')
    logging.info('Sign in successfully with Google account and redirect to %s...' % redirect)
    return 'redirect:%s' % redirect
 def test_create_duplicate_users(self):
     email = '*****@*****.**'
     password = hashlib.md5('random-password').hexdigest()
     bob1 = store.create_user(store.ROLE_EDITOR, email, password, 'Bob1')
     self.assertFalse(bob1 is None)
     func = lambda: store.create_user(store.ROLE_CONTRIBUTOR, email,
                                      password, 'Bob2')
     self.assertRaises(ValidationError, func)
     self.assertRaises(ValidationError, func)
     # get by email, should be only one: Bob1
     us = store.User.all().filter('email =', email).fetch(100)
     self.assertEquals(1, len(us))
     u = store.get_user_by_email(email)
     self.assertEquals(store.ROLE_EDITOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals('Bob1', u.nicename)
 def test_create_and_get_user(self):
     email = '*****@*****.**'
     password = hashlib.md5('admin-password').hexdigest()
     nicename = 'Admin'
     admin = store.create_user(store.ROLE_ADMINISTRATOR, email, password,
                               nicename)
     self.assertFalse(admin is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, admin.role)
     self.assertEquals(email, admin.email)
     self.assertEquals(password, admin.password)
     self.assertEquals(nicename, admin.nicename)
     # get by email:
     u = store.get_user_by_email(email)
     self.assertFalse(u is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals(password, u.password)
     self.assertEquals(nicename, u.nicename)
     # get by key:
     u = store.get_user_by_key(admin.id)
     self.assertFalse(u is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals(password, u.password)
     self.assertEquals(nicename, u.nicename)
     # load non-exist user:
     u = store.get_user_by_email('*****@*****.**')
     self.assertTrue(u is None)
Beispiel #5
0
 def test_create_and_get_user(self):
     email = "*****@*****.**"
     password = hashlib.md5("admin-password").hexdigest()
     nicename = "Admin"
     admin = store.create_user(store.ROLE_ADMINISTRATOR, email, password, nicename)
     self.assertFalse(admin is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, admin.role)
     self.assertEquals(email, admin.email)
     self.assertEquals(password, admin.password)
     self.assertEquals(nicename, admin.nicename)
     # get by email:
     u = store.get_user_by_email(email)
     self.assertFalse(u is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals(password, u.password)
     self.assertEquals(nicename, u.nicename)
     # get by key:
     u = store.get_user_by_key(admin.id)
     self.assertFalse(u is None)
     self.assertEquals(store.ROLE_ADMINISTRATOR, u.role)
     self.assertEquals(email, u.email)
     self.assertEquals(password, u.password)
     self.assertEquals(nicename, u.nicename)
     # load non-exist user:
     u = store.get_user_by_email("*****@*****.**")
     self.assertTrue(u is None)
Beispiel #6
0
def do_register(**kw):
    ctx = kw['context']
    email = ctx.get_argument('email', '').lower()
    password = ctx.get_argument('password')
    nicename = ctx.get_argument('nicename')
    role = int(store.get_setting('default_role', 'site', `store.ROLE_SUBSCRIBER`))
    error = ''
    try:
        user = store.create_user(role, email, password, nicename)
        value = cookie.make_sign_in_cookie(user.id, password, 86400)
        ctx.set_cookie(cookie.AUTO_SIGNIN_COOKIE, value)
        return 'redirect:/manage/'
    except store.UserAlreadyExistError:
        error = 'Email is already registered by other'
    except StandardError:
        logging.exception('Error when create user')
        error = 'Unexpected error occurred'
    return {
            '__view__' : 'register.html',
            'error' : error,
            'site' : _get_site_info(),
    }
Beispiel #7
0
def do_register(**kw):
    ctx = kw['context']
    email = ctx.get_argument('email', '').lower()
    password = ctx.get_argument('password')
    nicename = ctx.get_argument('nicename')
    role = int(
        store.get_setting('default_role', 'site', ` store.ROLE_SUBSCRIBER `))
    error = ''
    try:
        user = store.create_user(role, email, password, nicename)
        value = cookie.make_sign_in_cookie(user.id, password, 86400)
        ctx.set_cookie(cookie.AUTO_SIGNIN_COOKIE, value)
        return 'redirect:/manage/'
    except store.UserAlreadyExistError:
        error = 'Email is already registered by other'
    except StandardError:
        logging.exception('Error when create user')
        error = 'Unexpected error occurred'
    return {
        '__view__': 'register.html',
        'error': error,
        'site': _get_site_info(),
    }
Beispiel #8
0
def _create_user():
    return store.create_user(store.ROLE_ADMINISTRATOR, '*****@*****.**', 'password', 'Bob')