| @@ 77-98 (lines=22) @@ | ||
| 74 | * @param string $verificationCode |
|
| 75 | * @return mixed |
|
| 76 | */ |
|
| 77 | public function verification_check(string $verificationCode) { |
|
| 78 | //user is trying to validate their email for signup, check if verification code is still valid/exists |
|
| 79 | $query = $this->db->select('email, verification_code_time') |
|
| 80 | ->from('auth_signup_verification') |
|
| 81 | ->where(array('verification_code' => $verificationCode)) |
|
| 82 | ->get(); |
|
| 83 | ||
| 84 | $return = FALSE; |
|
| 85 | if($query->num_rows() > 0) { |
|
| 86 | $result = $query->row(); |
|
| 87 | ||
| 88 | if((time() - $result->verification_code_time) > 46400000) { |
|
| 89 | //expired, past the 24hr mark |
|
| 90 | ||
| 91 | //TODO: Remove from DB, send user error that verification expired. |
|
| 92 | } else { |
|
| 93 | //not expired, verification is valid, return email |
|
| 94 | $return = $result->email; |
|
| 95 | } |
|
| 96 | } |
|
| 97 | return $return; |
|
| 98 | } |
|
| 99 | ||
| 100 | /** |
|
| 101 | * @param string $email |
|
| @@ 60-86 (lines=27) @@ | ||
| 57 | * |
|
| 58 | * @return mixed |
|
| 59 | */ |
|
| 60 | public function find_email_from_identity(string $identity) { |
|
| 61 | //login allows using email or username, but ion_auth doesn't support this |
|
| 62 | //check if identity is email, and if not, try and find it |
|
| 63 | //returns: email or FALSE |
|
| 64 | //CHECK: How should we handle invalid emails being passed to this? |
|
| 65 | $email = $identity; |
|
| 66 | ||
| 67 | if(!strpos($identity, '@')) { |
|
| 68 | //identity does not contain @, assume username |
|
| 69 | $this->load->database(); |
|
| 70 | ||
| 71 | $query = $this->db->select('email') |
|
| 72 | ->from('auth_users') |
|
| 73 | ->where('username', $identity) |
|
| 74 | ->get(); |
|
| 75 | ||
| 76 | if($query->num_rows() > 0) { |
|
| 77 | //username exists, grab email |
|
| 78 | $email = $query->row('email'); |
|
| 79 | }else{ |
|
| 80 | //username doesn't exist, return FALSE |
|
| 81 | $email = FALSE; |
|
| 82 | } |
|
| 83 | } |
|
| 84 | ||
| 85 | return $email; |
|
| 86 | } |
|
| 87 | ||
| 88 | public function get_user_by_username(string $username) { |
|
| 89 | $user = NULL; |
|