Created
May 6, 2014 20:47
-
-
Save theJasonJones/86a7aae04635c662e2c3 to your computer and use it in GitHub Desktop.
CodeIgniter Create account method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function create_account() { | |
// Check the session. Same as before. | |
if ($this->session->userdata('logged_in')) { | |
$session_data = $this->session->userdata('logged_in'); | |
} else { redirect('login', 'refresh'); } | |
// Set initial state of the form in the create_account view. | |
$data['message'] = "Create a New Admin Account"; | |
// Check if the form has submitted. | |
if (isset($_POST['username']) && isset($_POST['password'])) { | |
// load the user model | |
$this->load->model('user'); | |
// call the models "create_account" function with the form data. | |
$account = $this->user->create_account($_POST['username'], $_POST['password']); | |
// On error, report the error. | |
if (!$account) { $data['message'] = "This account already exists: " . $_POST['username']; } | |
// report successful account creation to the view. | |
else { $data['message'] = "Successfully created new admin account: ".$_POST['username']; } | |
} | |
// load the view elements | |
$this->load->view('header'); | |
$this->load->view('console', $session_data); | |
$this->load->view('configure'); | |
$this->load->view('create_account', $data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment