When writing or building functions
First I write the name and variables of the function.
public function email_login($email, $password) {
}
Then I start describing the algorithm of the function line by line every step.
public function email_login($email, $password) {
// check if email is existing
// if existing verify password
// if correct password return user information
// if not show response invalid_password
// if email is not existing show response email_not_found
}
Then I write the algorithm one by one checking if it is working in the program until the last step. And that's it I've completed building the full function.
public function email_login($email, $password) {
// check if email is existing
$this->db->where('email', $email);
$query = $this->db->get('users');
$user = $query->row_array();
// if existing verify password
if ($user != null) {
// if correct password return user information
if ($user["password"] == $password) {
return $user;
// if not show response invalid_password
} else {
return "invalid_password";
}
// if not show response email_not_found
} else {
return "email_not_found";
}
}
Top comments (0)