@@ -6,7 +6,7 @@ public function __construct()
66{
77parent ::__construct ();
88$ this ->load ->model ('auth_model ' );
9- if (!$ this ->auth_model ->current_user ()){
9+ if (!$ this ->auth_model ->current_user ()) {
1010redirect ('auth/login ' );
1111}
1212}
@@ -16,4 +16,72 @@ public function index()
1616$ data ['current_user ' ] = $ this ->auth_model ->current_user ();
1717$ this ->load ->view ('admin/setting ' , $ data );
1818}
19+
20+ public function upload_avatar ()
21+ {
22+ echo "comming soon! " ;
23+ }
24+
25+ public function remove_avatar ()
26+ {
27+ echo "comming soon! " ;
28+ }
29+
30+ public function edit_profile ()
31+ {
32+ $ this ->load ->library ('form_validation ' );
33+ $ this ->load ->model ('profile_model ' );
34+ $ data ['current_user ' ] = $ this ->auth_model ->current_user ();
35+
36+ if ($ this ->input ->method () === 'post ' ) {
37+ $ rules = $ this ->profile_model ->profile_rules ();
38+ $ this ->form_validation ->set_rules ($ rules );
39+
40+ if ($ this ->form_validation ->run () === FALSE ){
41+ return $ this ->load ->view ('admin/setting_edit_profile_form.php ' , $ data );
42+ }
43+
44+ $ new_data = [
45+ 'id ' => $ data ['current_user ' ]->id ,
46+ 'name ' => $ this ->input ->post ('name ' ),
47+ 'email ' => $ this ->input ->post ('email ' ),
48+ ];
49+
50+ if ($ this ->profile_model ->update ($ new_data )){
51+ $ this ->session ->set_flashdata ('message ' , 'Profile was updated ' );
52+ redirect (site_url ('admin/setting ' ));
53+ }
54+ }
55+
56+ $ this ->load ->view ('admin/setting_edit_profile_form.php ' , $ data );
57+ }
58+
59+ public function edit_password ()
60+ {
61+ $ this ->load ->library ('form_validation ' );
62+ $ this ->load ->model ('profile_model ' );
63+ $ data ['current_user ' ] = $ this ->auth_model ->current_user ();
64+
65+ if ($ this ->input ->method () === 'post ' ) {
66+ $ rules = $ this ->profile_model ->password_rules ();
67+ $ this ->form_validation ->set_rules ($ rules );
68+
69+ if ($ this ->form_validation ->run () === FALSE ){
70+ return $ this ->load ->view ('admin/setting_edit_password_form.php ' , $ data );
71+ }
72+
73+ $ new_password_data = [
74+ 'id ' => $ data ['current_user ' ]->id ,
75+ 'password ' => password_hash ($ this ->input ->post ('password ' ), PASSWORD_DEFAULT ),
76+ 'password_updated_at ' => date ("Y-m-d H:i:s " ),
77+ ];
78+
79+ if ($ this ->profile_model ->update ($ new_password_data )){
80+ $ this ->session ->set_flashdata ('message ' , 'Password was changed ' );
81+ redirect (site_url ('admin/setting ' ));
82+ }
83+ }
84+
85+ $ this ->load ->view ('admin/setting_edit_password_form.php ' , $ data );
86+ }
1987}
0 commit comments