diff --git a/IES-Bandung/app/Http/Controllers/ProfileController.php b/IES-Bandung/app/Http/Controllers/ProfileController.php index b5d7fff09efc10f65de6edcd21700ddfa5814061..f0e45a3b082194d8b9e500ac06456241033928f7 100644 --- a/IES-Bandung/app/Http/Controllers/ProfileController.php +++ b/IES-Bandung/app/Http/Controllers/ProfileController.php @@ -50,4 +50,18 @@ class ProfileController extends Controller return $this->controller->showProfile($username); } + public function editProfile(Request $request) { + $type = Auth::user()['type']; + if($type === "public"){ + $this->controller = new PublicUserController(); + } + else if($type === "vendor"){ + $this->controller = new VendorUserController(); + } + else{ + echo "Unknown User Type"; + exit(); + } + return $this->controller->editProfile($request); + } } diff --git a/IES-Bandung/app/Http/Controllers/VendorUserController.php b/IES-Bandung/app/Http/Controllers/VendorUserController.php index da11e788d675c4d9e1e89cb2e973156a54b76d57..6f0969a0b9afe6187f0347886b5e5ca1221eca12 100644 --- a/IES-Bandung/app/Http/Controllers/VendorUserController.php +++ b/IES-Bandung/app/Http/Controllers/VendorUserController.php @@ -13,7 +13,7 @@ use Auth; class VendorUserController extends Controller { - public function viewProfile($username) { + public function viewProfile ($username) { $editable = Auth::check() ? Auth::user()['username'] === $username : false; $user = VendorUser::getFullProfile($username); $objects = ObjectSell:: @@ -35,4 +35,35 @@ class VendorUserController extends Controller public function showProfile($username){ return $this->viewProfile($username); } + public function editProfile(Request $request) { + if(Auth::check()) { + $userId = Auth::user()['id']; + $user = User::find($userId); + $this->validate($request, [ + 'email' => 'required|email|max:255|unique:users,email,'.$user->id, + 'full_name' => 'required|max:255', + 'birth_date' => 'required|date', + 'birth_place' => 'required|max:255', + 'tel_no' => 'required|max:255', + 'place' => 'required' + ]); + + if($request->editPassword) { + $this->validate($request, [ + 'password' => 'required|min:6|confirmed' + ]); + } + VendorUser::updateVendorplace($userId, $request->place); + $user->full_name = $request->full_name; + $user->email = $request->email; + $user->tel_no = $request->tel_no; + $user->birth_place = $request->birth_place; + $user->birth_date = $request->birth_date; + if($request->editPassword) { + $user->password = bcrypt($request->password); + } + $user->save(); + } + return redirect('/profile'); + } } diff --git a/IES-Bandung/app/Http/routes.php b/IES-Bandung/app/Http/routes.php index f6673db222264b2bfd8c896c4d021fbb5f14739d..2665ad358582b2c41aa0439020ef1b1b12bc1247 100755 --- a/IES-Bandung/app/Http/routes.php +++ b/IES-Bandung/app/Http/routes.php @@ -23,7 +23,7 @@ Route::get('/home', 'HomeController@index'); Route::get('/profile', 'ProfileController@index'); Route::get('/profile/{username}', ['uses' => 'ProfileController@showProfile']); -Route::post('/profile/edit', ['uses' => 'PublicUserController@editProfile']); +Route::post('/profile/edit', ['uses' => 'ProfileController@editProfile']); // Vendor's object sell Route::post('/item/add', 'ObjectSellController@createObjectSell'); diff --git a/IES-Bandung/app/Model/VendorUser.php b/IES-Bandung/app/Model/VendorUser.php index 5fb2519cd1b87b0497f3f804047034dbee9deffa..b3e7b3cf52360e4ad7ba8c697089de4ed3365039 100644 --- a/IES-Bandung/app/Model/VendorUser.php +++ b/IES-Bandung/app/Model/VendorUser.php @@ -25,7 +25,7 @@ class VendorUser extends Model } public static function updateVendorplace($userId, $newplace) { - return $this->where($userId, '=', 'VendorUser.id')->update(array( + VendorUser::where('vendor_users.user_id', '=', $userId)->update(array( 'place' => $newplace )); } diff --git a/IES-Bandung/resources/views/vendorUser.blade.php b/IES-Bandung/resources/views/vendorUser.blade.php index 2181554e44ca2f10cfea0ebce67d5e026e16b56a..b7d468b0cb0343e55797e33bc80eb2f48694b948 100755 --- a/IES-Bandung/resources/views/vendorUser.blade.php +++ b/IES-Bandung/resources/views/vendorUser.blade.php @@ -31,12 +31,13 @@ </a> <div class="clear m-b"> <div class="m-b-sm m-t-sm"> - <span class="text22 text-white font-semibold">{{ $user->full_name }} {{ $rating }}</span> + <span class="text22 text-white font-semibold">{{ $user->full_name }}</span> <small class="m-l-sm text-info"><a href="#">{{ $user->email }}</a></small> </div> <div class=""> <span class="text12 m-b-md text-grey"><i class="text-white fa fa-map-marker text14 m-r-xs"></i> {{ $user->place }}</span> </div> + <span class="text18 text-white font-semibold">[mock] Rating : <?= $rating < 0 ? 'Belum dirating' : $rating ?></span> <p class="m-b m-t-sm"> <a href class="m-r-sm text-white btn-icon"><i class="text16 fa fa-twitter"></i></a> <a href class="m-r-sm text-white btn-icon"><i class="text16 fa fa-facebook-square"></i></a> @@ -268,6 +269,103 @@ </div> @endif + @if($editable) + + <div class="col-md-12"> + <div class="panel panel-default"> + <div class="panel-heading font-bold">Edit Profile</div> + <div class="panel-body"> + <form role="form" class="row" action="edit" method="POST"> + + {!! csrf_field() !!} + + <div class="col-sm-6"> + <div class="form-group"> + <label>Nama</label> + <input type="text" class="form-control" placeholder="Masukan Nama" value="{{ $user->full_name }}" name="full_name" required> + @if ($errors->has('full_name')) + <span class="help-block"> + <strong>{{ $errors->first('full_name') }}</strong> + </span> + @endif + </div> + <div class="form-group"> + <label>Nomor Ponsel</label> + <input type="text" class="form-control" placeholder="Masukkan Nomor Ponsel" value="{{ $user->tel_no }}" name="tel_no" required> + </div> + <div class="form-group"> + <label>Tempat Kelahiran</label> + <input type="text" class="form-control" placeholder="Masukkan Nomor Ponsel" value="{{ $user->birth_place }}" name="birth_place" required> + @if ($errors->has('birth_place')) + <span class="help-block"> + <strong>{{ $errors->first('birth_place') }}</strong> + </span> + @endif + </div> + <div class="form-group"> + <label>Tanggal Kelahiran</label> + <input type="text" class="form-control" placeholder="Masukkan Nomor Ponsel" value="{{ $user->birth_date }}" name="birth_date" required> + @if ($errors->has('birth_date')) + <span class="help-block"> + <strong>{{ $errors->first('birth_date') }}</strong> + </span> + @endif + </div> + <button type="submit" class="btn btn-sm btn-success">Update</button> + </div> + <div class="col-sm-6"> + <div class="form-group"> + <label>Tempat Jualan</label> + <input type="text" class="form-control" placeholder="Masukkan Nomor Ponsel" value="{{ $user->place }}" name="place" required> + @if ($errors->has('place')) + <span class="help-block"> + <strong>{{ $errors->first('place') }}</strong> + </span> + @endif + </div> + <div class="form-group"> + <label>E-mail</label> + <input type="email" class="form-control" placeholder="Masukkan E-mail" value="{{ $user->email }}" name ="email" required> + @if ($errors->has('email')) + <span class="help-block"> + <strong>{{ $errors->first('email') }}</strong> + </span> + @endif + </div> + + <div class="checkbox m-b-lg"> + <label class="checkbox-inline"> + <input id="checkpass" type="checkbox" name="editPassword"><i></i> Ganti Password + </label> + </div> + + <div class="form-group"> + <label>Password</label> + <input type="password" class="form-control passc" placeholder="Masukkan Password" disabled name="password"> + @if ($errors->has('password')) + <span class="help-block"> + <strong>{{ $errors->first('password') }}</strong> + </span> + @endif + </div> + + <div class="form-group"> + <label>Re-enter Password</label> + <input type="password" class="form-control passc" placeholder="Masukkan Kembali Password" disabled name="password_confirmation"> + @if ($errors->has('password_confirmation')) + <span class="help-block"> + <strong>{{ $errors->first('password_confirmation') }}</strong> + </span> + @endif + </div> + </div> + </form> + </div> + </div> + </div> + + @endif + </div> </div> </div>