diff --git a/app/Config/Email.php b/app/Config/Email.php index 0135018..9c77bbe 100644 --- a/app/Config/Email.php +++ b/app/Config/Email.php @@ -18,7 +18,7 @@ class Email extends BaseConfig /** * The mail sending protocol: mail, sendmail, smtp */ - public string $protocol = 'mail'; + public string $protocol = 'smtp'; /** * The server path to Sendmail. @@ -28,27 +28,27 @@ class Email extends BaseConfig /** * SMTP Server Address */ - public string $SMTPHost = ''; + public string $SMTPHost = 'smtp.gmail.com'; /** * SMTP Username */ - public string $SMTPUser = ''; + public string $SMTPUser = 'suseendhiran.1702117@srit.org'; /** * SMTP Password */ - public string $SMTPPass = ''; + public string $SMTPPass = 'zlquygyjcjacvuqr'; /** * SMTP Port */ - public int $SMTPPort = 25; + public int $SMTPPort = 465; /** * SMTP Timeout (in seconds) */ - public int $SMTPTimeout = 5; + public int $SMTPTimeout = 20; /** * Enable persistent SMTP connections @@ -58,7 +58,7 @@ class Email extends BaseConfig /** * SMTP Encryption. Either tls or ssl */ - public string $SMTPCrypto = 'tls'; + public string $SMTPCrypto = 'ssl'; /** * Enable word-wrap @@ -73,7 +73,7 @@ class Email extends BaseConfig /** * Type of mail, either 'text' or 'html' */ - public string $mailType = 'text'; + public string $mailType = 'html'; /** * Character set (utf-8, iso-8859-1, etc.) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 82bd447..65f2ad9 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -46,6 +46,9 @@ $routes->match(['get','post'],'/admin','Admin_controller::index'); $routes->match(['get'],'/admin_logout','Admin_controller::admin_logout'); //$routes->get('/', 'Member_controller::index'); +$routes->match(['get','post'],'/mail/(:any)','Sendmail_controller::index/$1'); +$routes->match(['get','post'],'/verify_email/(:any)','Sendmail_controller::verify_email/$1'); + /* * -------------------------------------------------------------------- * Additional Routing diff --git a/app/Controllers/Member_controller.php b/app/Controllers/Member_controller.php index 90d45ab..5eb607f 100644 --- a/app/Controllers/Member_controller.php +++ b/app/Controllers/Member_controller.php @@ -61,13 +61,28 @@ class Member_controller extends BaseController { //insert member details $MemberData = $this->request->getVar(); - $this->MemberModel->save($MemberData); - return redirect()->to(base_url()); + // Generate a random verification code + $verification_code = md5(uniqid()); + $MemberData['verification_code'] = $verification_code; + // print_r($MemberData);die(); + $insert_data = $this->MemberModel->save($MemberData); + if($insert_data) + { + // Send the verification email + return redirect()->to(base_url()."mail/".$this->request->getVar('email')."/".$verification_code); + } + else + { + // Show error message + echo 'Error in registering user. Please try again.'; + } + // return redirect()->to(base_url()); } return view('member_registration'); } + public function members_list() { $id = session()->get('logged_user'); diff --git a/app/Controllers/Sendmail_controller.php b/app/Controllers/Sendmail_controller.php new file mode 100644 index 0000000..87a9fbb --- /dev/null +++ b/app/Controllers/Sendmail_controller.php @@ -0,0 +1,67 @@ +session = session(); + $this->MemberModel = new Member_model(); + + } + public function index($to,$code) + { + echo '
Please click your email address to verify
'; + $email = \Config\Services::email(); + + $email->setFrom('suseendhiran.1702117@srit.org', 'suseendhiran'); + $email->setTo($to); + // $email->setCC('another@another-example.com'); + // $email->setBCC('them@their-example.com'); + $message = 'Please click the following link to verify your email address
'; + $message .= ''; + + $email->setSubject('Verify your email address'); + $email->setMessage($message); + if ($email->send()) { + return 1; + } else { + return 0; + } + + } + + public function verify_email($verification_code) + { + // Get the user data corresponding to the verification code + $user_data = $this->MemberModel->where('verification_code', $verification_code)->find(); + if($user_data) + { + // Update the users status + // $update_data = $this->MemberModel->update_status($user_data['id']); + $data['is_email_verified'] = 1; + $update_data = $this->MemberModel->where('id', $user_data[0]['id'] )->set($data)->update(); + if($update_data) + { + // Show success message + $this->session->set_flashdata('mail_success', "Your email has been verified. Please login to continue."); + return redirect()->to(base_url()); + } + else + { + // Show error message + echo 'Error in verifying email. Please try again.'; + } + } + else + { + // Show error message + echo 'Invalid verification code.'; + } + } + + +} \ No newline at end of file diff --git a/app/Models/Member_model.php b/app/Models/Member_model.php index 80b7097..0d8e850 100644 --- a/app/Models/Member_model.php +++ b/app/Models/Member_model.php @@ -7,7 +7,7 @@ class Member_model extends Model protected $table = 'member'; protected $primaryKey = 'id'; - protected $allowedFields = ['name', 'mobile','email','username', 'password', 'address' , 'city' , 'state' , 'country' , 'pincode' , 'is_email_verifyed' , 'created_by','updated_by']; + protected $allowedFields = ['name', 'mobile','email','username', 'password', 'address' , 'city' , 'state' , 'country' , 'pincode' , 'is_email_verified' , 'verification_code' , 'created_by','updated_by']; protected $beforeInsert = ['beforeInsert']; protected $beforeUpdate = ['beforeUpdate']; diff --git a/app/Views/member_login.php b/app/Views/member_login.php index ae79cb2..15613de 100644 --- a/app/Views/member_login.php +++ b/app/Views/member_login.php @@ -42,7 +42,7 @@