/** * create function. * * @access public * @return void */ public function create() { $this->output->enable_profiler(false); if (!$this->auth->loggedin()) { redirect('user/login'); } $uid = intval($this->auth->userid()); $user = $this->user_model->get_user($uid); $this->form_validation->set_rules('username', ucfirst(lang('username')), 'trim|required|is_unique[users.username]'); $this->form_validation->set_rules('email', ucfirst(lang('email_address')), 'trim|required|valid_email|is_unique[users.email]'); $this->form_validation->set_message('is_unique', '%s finns redan i systemet.'); $this->form_validation->set_error_delimiters('<small class="error">', '</small>'); $data['title'] = $this->system_model->get('app_name'); $heading = ucfirst(lang('create_user')); $data['breadcrumbs'] = array(array('data' => anchor('/', $data['title']), 'mode' => 'unavailable'), array('data' => anchor('admin', ucfirst(lang('administration')))), array('data' => anchor('admin/users', ucfirst(lang('users')))), array('data' => anchor('user/create', $heading), 'mode' => 'current')); $html = heading($heading, 1); if ($this->form_validation->run() == true) { $user = array(); $username = $this->input->post('username'); $firstname = $this->input->post('firstname'); $lastname = $this->input->post('lastname'); $email = $this->input->post('email'); $phone = $this->input->post('phone'); if ($username) { $user['username'] = $username; } if ($firstname) { $user['firstname'] = $firstname; } if ($lastname) { $user['lastname'] = $lastname; } if ($email) { $user['email'] = $email; } if ($phone) { $user['phone'] = $phone; } $user['password'] = very_random_string(); $id = $this->user_model->create_user($user); $html .= p('Grattis, nu har du lagt till användaren ' . $user['username'] . '!', 'lead'); $html .= p('Användaren registrerades med följande uppgifter:'); $html .= ul(array(strong('Användarnamn:') . nbs() . $user['username'], strong('E-postadress:') . nbs() . mailto($user['email'], $user['email']), strong('Förnamn:') . nbs() . $user['firstname'], strong('Efternamn:') . nbs() . $user['lastname'], strong('Telefonnummer:') . nbs() . $user['phone']), array('class' => 'no-bullet')); $html .= p('Ett tillfälligt lösenord har skapats åt ' . $user['username'] . ' som bara går att använda vid första inloggningen, se till' . ' att användaren får detta för att kunna logga in:'); $html .= ul(array(strong($user['password'])), array('class' => 'no-bullet')); $html .= button_anchor('user/create', ucfirst(lang('create_another_user'))); } else { $html .= $this->create_form(); } $data['html'] = $html; $this->system_model->view('template', $data); }
/** * create_user function. * * @access private * @return void */ private function create_user() { return $this->user_model->create_user(array('username' => 'test', 'password' => 'test', 'email' => '*****@*****.**', 'password' => very_random_string())); }