Example #1
0
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
Example #2
0
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'/remote_api'
  
  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  try:
    create_new_user(user_name, password, is_admin=is_admin)
    print_status('A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
Example #3
0
def accept(request, request_id):
    if request.method == 'POST':
        reguest = RegistrationRequest.get_by_id(request_id)
        if reguest:
            reguest.status = REQUEST_STATUS['accepted']
            reguest.put()
            password = passgen()
            try:
                new_user = create_new_user(
                    user_name = reguest.email,
                    password = password,
                    is_admin = False,
                    first_name = reguest.name,
                    telephone = reguest.telephone,
                    organization = reguest.organization,
                    address = reguest.address,
                    email = reguest.email
                )
                def txn():
                    taskqueue.add(url=url_for('reguest/admins/send_accept_to_user',
                                        request_id=reguest.key.id(),
                                        password = password),
                                        transactional=True)
                db.run_in_transaction(txn)
            except DuplicateKeyError:
                pass
    return redirect(url_for('reguest/admins/index'))
Example #4
0
def add_user(request):
    form = UserForm(initial={'password':gen_password(6)})
    if request.method == 'POST':
        if form.validate(request.form):
            user_name = request.form['user_name'].lower()
            new_user = create_new_user(user_name=user_name, password=request.form['password'])
            new_user.email=request.form['email']
            new_user.first_name = request.form['first_name']
            new_user.last_name = request.form['last_name']
            manager_key = request.form['manager']
            if manager_key:
                manager = Manager.get(manager_key)
                new_user.manager = manager
            try:
                new_user.newsletter_type = int(request.form['newsletter_type'])
            except:
                pass
            try:
                if request.form['activated'] == 'on':
                    new_user.activated = True
            except:
                new_user.activated = False
            try:
                if request.form['is_admin'] == 'on':
                    new_user.is_admin = True
            except:
                new_user.is_admin = False
            new_user.put()
            return redirect(url_for('admin/users'))

    return render_to_response('admin/add_user.html', {'form': form.as_widget()})
Example #5
0
  def test_login(self):
    from kay.auth import create_new_user
    create_new_user("foobar", "password", is_admin=False)
    response = self.client.get(url_for('auth_testapp/index'))
    self.assertEqual(response.status_code, 200)
    response = self.client.get(url_for('auth_testapp/secret'))
    self.assertEqual(response.status_code, 302)
    self.assert_(response.headers.get('Location').endswith(
        '/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret'))

    self.client.test_login(username='******')
    response = self.client.get(url_for('auth_testapp/secret'))
    self.assertEqual(response.status_code, 200)
    self.client.test_logout()
    response = self.client.get(url_for('auth_testapp/secret'))
    self.assertEqual(response.status_code, 302)
Example #6
0
    def test_login(self):
        from kay.auth import create_new_user
        create_new_user("foobar", "password", is_admin=False)
        response = self.client.get(url_for('auth_testapp/index'))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(url_for('auth_testapp/secret'))
        self.assertEqual(response.status_code, 302)
        self.assert_(
            response.headers.get('Location').endswith(
                '/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret'))

        self.client.test_login(username='******')
        response = self.client.get(url_for('auth_testapp/secret'))
        self.assertEqual(response.status_code, 200)
        self.client.test_logout()
        response = self.client.get(url_for('auth_testapp/secret'))
        self.assertEqual(response.status_code, 302)
Example #7
0
 def setUp(self):
     from kay.auth import create_new_user
     s = LazySettings(settings_module='kay.tests.datastore_settings')
     app = get_application(settings=s)
     self.client = Client(app, BaseResponse)
     create_new_user("foobar", "password", is_admin=False)
Example #8
0
 def setUp(self):
   from kay.auth import create_new_user
   s = LazySettings(settings_module='kay.tests.datastore_settings')
   app = get_application(settings=s)
   self.client = Client(app, BaseResponse)
   create_new_user("foobar", "password", is_admin=False)