@@ -63,11 +63,11 @@ public function insert(){
63
63
public function profile (){
64
64
$ user = authorize (1 );
65
65
66
- $ page = array (
66
+ $ page = [
67
67
'user ' => $ user ,
68
68
'page_content ' => 'user/profile ' ,
69
69
'page_title ' => 'Minha Conta ' ,
70
- ) ;
70
+ ] ;
71
71
72
72
$ this ->load ->view ('public/base ' , $ page );
73
73
}
@@ -77,36 +77,44 @@ public function updateAccount(){
77
77
78
78
$ this ->load ->model ('UserModel ' );
79
79
80
- $ extension = explode (". " , $ _FILES ['photo ' ]['name ' ]);
81
- $ filename = $ user ->id_user .". " .end ($ extension );
82
-
83
- $ config ['upload_path ' ] = './assets/img/users/ ' ;
84
- $ config ['allowed_types ' ] = 'gif|jpg|png ' ;
85
- $ config ['max_size ' ] = 100 ;
86
- $ config ['max_width ' ] = 1024 ;
87
- $ config ['max_height ' ] = 768 ;
88
- $ config ['file_name ' ] = $ filename ;
89
-
90
- $ this ->load ->library ('upload ' , $ config );
91
-
92
- if (!$ this ->upload ->do_upload ('photo ' )){
93
- $ this ->session ->set_flashdata ('error ' , 'Problemas com o upload da imagem, tente outra. ' );
94
- redirect ('/perfil ' );
95
- }
96
-
97
80
$ newEmail = filter_var ($ this ->input ->post ('email ' ), FILTER_VALIDATE_EMAIL );
98
81
if ($ newEmail != $ user ->email && $ this ->UserModel ->searchByEmail ($ newEmail )){
99
82
$ this ->session ->set_flashdata ('error ' , 'Já existe conta com este email ' );
100
83
redirect ('/perfil ' );
101
84
}
102
85
103
86
$ user ->name = html_escape ($ this ->input ->post ('name ' ));
104
- $ user ->photo = $ filename ;
105
87
$ user ->email = $ newEmail ;
106
88
if ($ this ->input ->post ('password ' ) != "" ){
107
89
$ user ->password = password_hash ($ this ->input ->post ('password ' ), PASSWORD_BCRYPT );
108
90
}
109
91
92
+ if ($ _FILES ['photo ' ]['tmp_name ' ] != "" ){
93
+ $ extension = explode (". " , $ _FILES ['photo ' ]['name ' ]);
94
+ $ filename = $ user ->id_user .". " .end ($ extension );
95
+
96
+ if (file_exists ('./assets/img/users/ ' .$ userphoto )){
97
+ unlink ('./assets/img/users/ ' .$ user ->photo );
98
+ }
99
+
100
+ $ config ['upload_path ' ] = './assets/img/users/ ' ;
101
+ $ config ['allowed_types ' ] = 'gif|jpg|png ' ;
102
+ $ config ['max_size ' ] = 100 ;
103
+ $ config ['max_width ' ] = 1024 ;
104
+ $ config ['max_height ' ] = 1024 ;
105
+ $ config ['file_name ' ] = $ filename ;
106
+
107
+ $ this ->load ->library ('upload ' , $ config );
108
+
109
+ if (!$ this ->upload ->do_upload ('photo ' )){
110
+ $ this ->session ->set_flashdata ('error ' , 'Problemas com o upload da imagem, tente outra. ' );
111
+ redirect ('/perfil ' );
112
+ }
113
+
114
+ $ user ->photo = $ filename ;
115
+ }
116
+
117
+
110
118
$ this ->UserModel ->updateById ($ user , $ user ->id_user );
111
119
112
120
$ this ->session ->set_flashdata ('success ' , 'Perfil Atualizado ' );
0 commit comments