diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e05563b..8aef1a7 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -36,6 +36,12 @@ $routes->match(['get'],'/members_list','Member_controller::members_list'); $routes->match(['get'],'/member_edit/(:any)','Member_controller::member_edit/$1'); $routes->match(['post'],'/member_edit','Member_controller::member_edit'); $routes->match(['get','post'],'/member_add','Member_controller::member_add'); +$routes->match(['get','post'],'/set_password/(:any)','Member_controller::set_password/$1'); +$routes->match(['get','post'],'/update_password','Member_controller::update_password'); +$routes->match(['get','post'],'/change_password','Member_controller::change_password'); +$routes->match(['get','post'],'/change_password_form','Member_controller::change_password_form'); + + $routes->match(['get','post'],'/admin','Admin_controller::index'); @@ -46,6 +52,7 @@ $routes->match(['post'],'/user_edit','Admin_controller::user_edit'); $routes->match(['get','post'],'/user_add','Admin_controller::user_add'); $routes->match(['get'],'/admin_profile/(:any)','Admin_controller::admin_profile/$1'); $routes->match(['post'],'/admin_profile','Admin_controller::admin_profile'); +$routes->match(['post'],'/profilepic','Admin_controller::profilepic_insert'); $routes->match(['get'],'/admin_home','Dashboard::admin_home'); $routes->match(['get'],'/member_home','Dashboard::member_home'); @@ -54,9 +61,13 @@ $routes->match(['get'],'/member_home','Dashboard::member_home'); $routes->match(['get'],'fetch_country','Common_controller::fetch_country'); $routes->match(['get','post'],'fetch_state','Common_controller::fetch_state'); $routes->match(['get','post'],'fetch_city','Common_controller::fetch_city'); +$routes->match(['get','post'],'/check_if_mail_exists','Common_controller::check_if_mail_exists'); + $routes->match(['get','post'],'/mail/(:any)','Sendmail_controller::index/$1'); $routes->match(['get','post'],'/verify_email/(:any)','Sendmail_controller::verify_email/$1'); +$routes->match(['get','post'],'/forgot_password','Sendmail_controller::forgot_password'); + /* * -------------------------------------------------------------------- diff --git a/app/Controllers/Admin_controller.php b/app/Controllers/Admin_controller.php index 69aa839..23204be 100644 --- a/app/Controllers/Admin_controller.php +++ b/app/Controllers/Admin_controller.php @@ -9,12 +9,11 @@ class Admin_controller extends BaseController public $session; public function __construct() { - $this->session = session(); $this->UserModel = new User_model(); $this->dModel = new Dashboard_model(); $this->cModel = new Common_model(); - helper(['form']); + helper(['form', 'url']); } public function index() { @@ -154,11 +153,57 @@ class Admin_controller extends BaseController ->where('md5(users.id)', $user_id ) ->find(); - print_r($data);die(); + // print_r($data);die(); echo view('layout/header',$userdata); - echo view('user_form',$data); + echo view('profile',$data); echo view('layout/footer'); + } + + public function profilepic_insert() + { + + if($this->request->getmethod() == 'post') + { + $action = $this->request->getVar(); + // print_r($action);die(); + $id = $this->request->getVar('id'); + //file upload confic + $user_image['upload_path'] = base_url().'public/assets/images/users/'; + $user_image['allowed_types'] = 'jpg|png|jpeg'; + $user_image['max_size'] = 80000; + //upload + print_r($this->request->getFile('profile'));die(); + // $this->load->library('upload', $user_image); + // $this->upload->initialize($user_image); + if ($this->request->getPost('profile')) + { + $uploadPath = base_url().'public/assets/images/users/'; + $fileName = $this->request->getPost('profile')->move($uploadPath); + if ($fileName) + { + // Store the file name into the database + $data = [ + 'filename' => $fileName + ]; + echo $fileName; + // Do whatever you need with the data + } + // $error = array('error' => $this->upload->display_errors()); + // print_r($error);die(); + // echo false; + // } + // else + // { + // $upload_user_image = $this->upload->data(); + // $action['profile'] = $upload_user_image['file_name']; + // $userData = $this->UserModel->where('id', $id )->set($action)->update(); + // echo true; + } + + + } + } // ----------------------------------------------- } diff --git a/app/Controllers/Common_controller.php b/app/Controllers/Common_controller.php index 70b5bfc..99d3baa 100644 --- a/app/Controllers/Common_controller.php +++ b/app/Controllers/Common_controller.php @@ -4,6 +4,7 @@ namespace App\Controllers; use App\Models\User_model; use App\Models\Dashboard_model; use App\Models\Common_model; +use App\Models\Member_model; class Common_controller extends BaseController { public $session; @@ -11,6 +12,7 @@ class Common_controller extends BaseController { $this->session = session(); + $this->MemberModel = new Member_model(); $this->UserModel = new User_model(); $this->dModel = new Dashboard_model(); $this->cModel = new Common_model(); @@ -42,6 +44,25 @@ class Common_controller extends BaseController echo $this->cModel->fetch_city($this->request->getVar('state_id')); } } + + function check_if_mail_exists() + { + if($this->request->getVar('table')) + { + if($this->request->getVar('table') == 'member') + $data = $this->MemberModel->where('email', $this->request->getVar('email'))->find(); + else if($this->request->getVar('table') == 'users') + $data = $this->UserModel->where('email', $this->request->getVar('email'))->find(); + if ($data) + { + echo true; + } + else + { + echo false; + } + } + } diff --git a/app/Controllers/Member_controller.php b/app/Controllers/Member_controller.php index f7061b8..8c03bc6 100644 --- a/app/Controllers/Member_controller.php +++ b/app/Controllers/Member_controller.php @@ -174,6 +174,84 @@ class Member_controller extends BaseController } + public function forgot_password() + { + if($this->request->getmethod() == 'get') + { + return view('forgot_password.php'); + } + else if($this->request->getmethod() == 'post') + { + + $email = $this->request->getVar('email'); + $user_data = $this->MemberModel->where('email', $email)->find(); + if ($user_data) + { + $otp = rand(1000 , 9999 ); + // $sendmail_controller = new Sendmail_controller(); + $get_data = $Sendmail_controller->index($this->request->getVar('email') , $otp , 2 ); + $data['status'] = 'success'; + $data['otp'] = $otp; + echo json_encode($data); + } + else + { + $data['status'] = 'failed'; + echo json_encode($data); + } + + } + } + + public function change_password_form() + { + if($this->request->getmethod() == 'post') + { + $otp = $this->request->getVar('otp'); + $verify_otp = $this->request->getVar('verify_otp'); + if ($otp == $verify_otp) + { + $email = $this->request->getVar('email'); + $user_data = $this->MemberModel->where('email', $email)->find(); + $this->session->setTempdata('id',$user_data[0]['id'],3); + $this->session->setTempdata('email',$user_data[0]['email'],3); + $this->session->setTempdata('mail_success', "OTP verification sucessfully",3); + return view('set_password.php'); + } + else + { + $this->session->setTempdata('error', "You entered wrong OTP.Please retry",3); + return view('forgot_password.php'); + } + } + } + + + public function set_password($id) + { + if($this->request->getmethod() == 'get') + { + $user_data = $this->MemberModel->where('md5(id)', $id)->find(); + $this->session->setTempdata('id',$user_data[0]['id'],3); + $this->session->setTempdata('email',$user_data[0]['email'],3); + $this->session->setTempdata('mail_success', "Email verification sucessfully",3); + return view('set_password.php'); + } + } + + public function update_password() + { + if($this->request->getmethod() == 'post') + { + $MemberData = $this->request->getVar(); + $member_id = $this->request->getVar('id'); + $this->MemberModel->where('id', $member_id )->set($MemberData)->update(); + $this->session->setTempdata('mail_success', "Password set sucessfully",3); + return redirect()->to(base_url()); + } + } + + // ----------------------------------------------- } diff --git a/app/Controllers/Sendmail_controller.php b/app/Controllers/Sendmail_controller.php index 45688da..311a3be 100644 --- a/app/Controllers/Sendmail_controller.php +++ b/app/Controllers/Sendmail_controller.php @@ -14,15 +14,19 @@ class Sendmail_controller extends BaseController } public function index($to,$code,$return) { - $email = \Config\Services::email(); + $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->setTo($to); + if ($return == 2) + { + $message = $code; + } + else + { + $message = 'Please click the following link to verify your email address
'; + $message .= ''; + } $email->setSubject('Verify your email address'); $email->setMessage($message); if ($email->send()) @@ -31,15 +35,11 @@ class Sendmail_controller extends BaseController { $this->session->setTempdata('mail_success', "Please check your mail to verify",3); // return redirect()->to(base_url()); - } - else - { - return 0; } } else { - return 0; + echo 0; } } @@ -57,8 +57,9 @@ class Sendmail_controller extends BaseController if($update_data) { // Show success message - $this->session->setTempdata('mail_success', "Email verification sucessfully.",3); - return redirect()->to(base_url()); + // $this->session->setTempdata('mail_success', "Email verification sucessfully.",3); + // return redirect()->to(base_url()); + return redirect()->to(base_url()."set_password/".md5($user_data[0]['id'])); } else @@ -74,5 +75,33 @@ class Sendmail_controller extends BaseController } } + public function forgot_password() + { + if($this->request->getmethod() == 'get') + { + return view('forgot_password.php'); + } + else if($this->request->getmethod() == 'post') + { + + $email = $this->request->getVar('email'); + $user_data = $this->MemberModel->where('email', $email)->find(); + if ($user_data) + { + $otp = rand(1000 , 9999); + $this->index($this->request->getVar('email') , $otp , 2 ); + $data['status'] = 'success'; + $data['otp'] = $otp; + echo json_encode($data); + } + else + { + $data['status'] = 'failed'; + echo $data; + } + + } + } + } \ No newline at end of file diff --git a/app/Models/User_model.php b/app/Models/User_model.php index 9cfa485..4a37b41 100644 --- a/app/Models/User_model.php +++ b/app/Models/User_model.php @@ -7,7 +7,7 @@ class User_model extends Model protected $table = 'users'; protected $primaryKey = 'id'; - protected $allowedFields = ['role','name', 'mobile','email', 'password', 'address' , 'city' , 'state' , 'country' , 'pincode' ,'created_at','updated_at']; + protected $allowedFields = ['role','name', 'mobile', 'profile' , 'email', 'password', 'address' , 'city' , 'state' , 'country' , 'pincode' ,'created_at','updated_at']; protected $beforeInsert = ['beforeInsert']; protected $beforeUpdate = ['beforeUpdate']; diff --git a/app/Views/forgot_password.php b/app/Views/forgot_password.php new file mode 100644 index 0000000..af4da2c --- /dev/null +++ b/app/Views/forgot_password.php @@ -0,0 +1,132 @@ + + + + +" class="">Forgot your password?
Don't have an account? " class="text-primary font-weight-medium ml-1">Sign Up
| Name : | += $userList[0]['name'] ?> | +
|---|---|
| Mobile : | += $userList[0]['mobile'] ?> | +
| Email : | += $userList[0]['email'] ?> | +
| Location : | += $userList[0]['address'] ?> , = $userList[0]['city_name'] ?> , = $userList[0]['state_name'] ?> , = $userList[0]['country_name'] ?> - = $userList[0]['pincode'] ?> | +
+
+ + +