Make an account admin.

        Flag an existing user as an admin within the account.
322415
def make_account_admin(self, user_id, account_id, role=None, role_id=None, send_confirmation=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - account_id
        """ID"""
        path["account_id"] = account_id

        # REQUIRED - user_id
        """The id of the user to promote."""
        data["user_id"] = user_id

        # OPTIONAL - role
        """(deprecated)
        The user's admin relationship with the account will be created with the
        given role. Defaults to 'AccountAdmin'."""
        if role is not None:
            data["role"] = role

        # OPTIONAL - role_id
        """The user's admin relationship with the account will be created with the
        given role. Defaults to the built-in role for 'AccountAdmin'."""
        if role_id is not None:
            data["role_id"] = role_id

        # OPTIONAL - send_confirmation
        """Send a notification email to
        the new admin if true. Default is true."""
        if send_confirmation is not None:
            data["send_confirmation"] = send_confirmation

        self.logger.debug("POST /api/v1/accounts/{account_id}/admins with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("POST", "/api/v1/accounts/{account_id}/admins".format(**path), data=data, params=params, single_item=True)
760181
def create_user(email, password, active, confirmed_at, send_email):
    
    if confirmed_at == 'now':
        confirmed_at = security.datetime_factory()
    user = user_manager.create(email=email, password=password, active=active,
                               confirmed_at=confirmed_at)
    if click.confirm(f'Are you sure you want to create {user!r}?'):
        security_service.register_user(user, allow_login=False, send_email=send_email)
        user_manager.save(user, commit=True)
        click.echo(f'Successfully created {user!r}')
    else:
        click.echo('Cancelled.')
216078
private function createAdminUser()
    {
        $user = factory(User::class)->create(
            [
            'firstName' => $this->ADMIN_FIRST_NAME,
            'lastName' => $this->ADMIN_LAST_NAME,
            'slug' => str_slug($this->ADMIN_FIRST_NAME.'-'.$this->ADMIN_LAST_NAME),
            'email' => $this->ADMIN_EMAIL,
            'password' => Hash::make($this->ADMIN_PASSWORD),
            'isActive' => true
            ]
        );

        // assign role
        $user->assignRoles(UserGroup::getAdminGroup()->groupID, true);
    }
922515
def add_user(self, user, is_admin=False):
        
        users_count = self.users.all().count()
        if users_count == 0:
            is_admin = True
        # TODO get specific org user?
        org_user = self._org_user_model.objects.create(
            user=user, organization=self, is_admin=is_admin
        )
        if users_count == 0:
            # TODO get specific org user?
            self._org_owner_model.objects.create(
                organization=self, organization_user=org_user
            )

        # User added signal
        user_added.send(sender=self, user=user)
        return org_user
690336
def AuthorizeUser(self, user, subject):
    """"""

    user_set = self.authorized_users.setdefault(subject, set())
    user_set.add(user)
618904
def role_add(user, role):
    '''
    
    '''
    ret = {}

    ## validate roles
    roles = role.split(',')
    known_roles = role_list().keys()
    valid_roles = [r for r in roles if r in known_roles]
    log.debug(
        'rbac.role_add - roles=%s, known_roles=%s, valid_roles=%s',
        roles,
        known_roles,
        valid_roles,
    )

    ## update user roles
    if valid_roles:
        res = __salt__['cmd.run_all']('usermod -R "{roles}" {login}'.format(
            login=user,
            roles=','.join(set(role_get(user) + valid_roles)),
        ))
        if res['retcode'] > 0:
            ret['Error'] = {
                'retcode': res['retcode'],
                'message': res['stderr'] if 'stderr' in res else res['stdout']
            }
            return ret

    ## update return value
    active_roles = role_get(user)
    for r in roles:
        if r not in valid_roles:
            ret[r] = 'Unknown'
        elif r in active_roles:
            ret[r] = 'Added'
        else:
            ret[r] = 'Failed'

    return ret
1351439
def handle(self, *args, **options):
        """"""
        try:
            admin = User.objects.get(username='admin')
        except User.DoesNotExist:
            admin = User(
                username='admin',
                first_name='admin',
                last_name='admin',
                email='admin@localhost.localdomain',
                is_staff=True,
                is_active=True,
                is_superuser=True,
            )
        admin.set_password('admin')
        admin.save()
178766
def _is_admin(user_id):
    
    user = get_session().query(User).filter(User.id==user_id).one()

    if user.is_admin():
        return True
    else:
        return False
696254
def handle_existing_user(self, provider, user, access, info):
        ""
        login(self.request, user)
        return redirect(self.get_login_redirect(provider, user, access))
1116424
def promote
      # add the administrator flag to the selected user.
      if @user.system_admin?
        flash[:warning] = "User #{@user} is already an administrator."
        unless inline_request?
          redirect_to users_path and return
        end
      else
        if @user.update(system_admin: true)
          flash[:success] = "User #{@user} has been promoted to administrator."
        else
          flash[:danger] = "Failed to promote user #{@user}."
        end
      end

      if inline_request?
        render 'show', formats: [ :json ]
      else
        redirect_to users_path
      end
    end
1144723
def create
      @user = User.new(user_params.except(:user_roles))
      authorize! :create, @user
      build_user_roles(params)

      if @user.save
        redirect_to @user,
                    notice: "User was successfully created."
      else
        render :new
      end
    end
669781
protected function createAdminUser()
    {
        try {
            factory(get_class(app('App\User')))->create([
                    "name" => env('ADMIN_USER', $this->username()),
                    "email" => env('ADMIN_EMAIL', $this->email()),
                    "password" => bcrypt(env('ADMIN_PWD', '123456'))]);
        } catch (\Illuminate\Database\QueryException $exception) {
        }
    }
247785
def create_user(self, **kwargs):
        """"""
        kwargs = self._prepare_create_user_args(**kwargs)
        user = self.user_model(**kwargs)
        return self.put(user)
873840
def grant_admin_privileges(self, username):
        
        text = "GRANT ALL PRIVILEGES TO {0}".format(quote_ident(username))
        self.query(text, method="POST")
809477
def UpdateUser(username, password=None, is_admin=False):
  """"""
  user_type, password = _GetUserTypeAndPassword(
      username, password=password, is_admin=is_admin)
  grr_api = maintenance_utils.InitGRRRootAPI()
  grr_user = grr_api.GrrUser(username).Get()
  grr_user.Modify(user_type=user_type, password=password)
74627
def user(context, name, email):
    """"""
    existing_user = context.obj['store'].user(email)
    if existing_user:
        click.echo(existing_user.to_dict())
    elif name:
        new_user = context.obj['store'].add_user(name, email)
        click.echo(click.style(f"New user added: {email} ({new_user.id})", fg='green'))
    else:
        click.echo(click.style('User not found', fg='yellow'))
1275932
def cmd(send, msg, args):
    
    args['db'].query(Permissions).update({"registered": False})
    args['handler'].get_admins()
    send("Verified admins reset.")