Browse Source

Teacher Profile

Shah Rakibur Rahaman 2 years ago
parent
commit
e8205f79c4

+ 40 - 3
app/Http/Controllers/AjaxController.php

@@ -20,10 +20,47 @@ class AjaxController extends Controller
 
 	public function post($name, Request $req)
 	{
-		if($name =='send_apply_student_teacher_email') {  
-			 
+		if($name =='teacher_change_password') {  
+
+			$validator=\Validator::make($req->all(), [
+                'old_password'=>'required',
+                'new_password_confirmation'=>'required',
+                'new_password'=>[
+                    'required',
+                    'confirmed',
+                    'min:8',
+                    //'regex:/[a-z]/',      
+                    //'regex:/[A-Z]/',      
+                    //'regex:/[0-9]/',      
+                    //'regex:/[@$!%*#?&]/',
+                ]
+            ]);
+			//  [
+            //     'regex' => 'The :attribute must contain at least one lowercase, uppercase, digit and special character.'
+            // ]);
+
+            if($validator->fails()){
+                $errors=$validator->errors()->all();
+                return response(['msg'=>$errors[0]], 422);
+            }
+
+            $user=auth_user('teacher'); 
+
+            if(\Illuminate\Support\Facades\Hash::check($req->old_password, $user->password)) {
+                
+                $user->password=bcrypt($req->new_password);
+                $user->update();
+
+                return ['msg'=>'Your login password updated successfully!. Please use your new password for next time login.'];
+
+            }else{
+
+                return response(
+                    ['msg'=>'Sorry!, old password does not matched with login credential.'],
+                    403
+                );
 
-            return ['msg'=>'Email send successfully.'];
+            } 
 
 		}  
 	}

+ 1 - 1
app/Http/Controllers/TeacherHomeController.php

@@ -16,7 +16,7 @@ class TeacherHomeController extends Controller
     public function teacher_profile(Request $request)
     {   $user = Auth::guard('teacher')->user();
         $students = StudentProposal::where('teacher_id',$user->id)->get(); 
-        return view('teacher_profile',compact('students'));
+        return view('teacher_profile',compact('students','user'));
     }
 
     

+ 80 - 10
resources/views/teacher_profile.blade.php

@@ -48,6 +48,11 @@
         <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200;300&display=swap" rel="stylesheet">
         <link rel="stylesheet" href="{{asset('web/css/datepicker.min.css')}}">
         <link rel="stylesheet" href="{{asset('web/css/sweetalert/sweetalert.css')}}">
+        {{-- Ajax Form Submit --}}
+        <link href="{{ asset('css/noty/lib/noty.css') }}" rel="stylesheet" type="text/css">
+        <link href="{{ asset('css/noty/lib/themes/sunset.css') }}" rel="stylesheet" type="text/css">
+        <link href="{{ asset('css/flatpickr/dist/flatpickr.min.css') }}" rel="stylesheet" type="text/css">
+        <link href="{{ asset('css/wait-me/waitMe.min.css')}}"  rel="stylesheet" type="text/css"> 
     </head>
     <style>
 
@@ -855,20 +860,20 @@ tbody, td, tfoot, th, thead, tr {
                                                         <div class="single_glance_row mt-5">
                                                             <span class="title" style="font-size:11px; font-weight: 600;">Name :</span>
                                                             <span class="tbl2 mb-2">
-                                                                demo1
+                                                                {{$user->first_name}} {{$user->last_name}}
                                                             </span>
                                                         </div>
                                                         <div class="single_glance_row mt-1">
                                                             <span class="title" style="font-size:11px; font-weight: 600;">Email :</span>
-                                                            <span style="font-size: 11px; color: #868e96;">ab@mail.com</span>
+                                                            <span style="font-size: 11px; color: #868e96;">{{$user->email}}</span>
                                                         </div>
                                                         <div class="single_glance_row mt-1" style="display: flex;">
                                                                 <span class="title" style="font-size:11px; font-weight: 600;">University Name :</span>
-                                                                <span style="font-size: 11px; color: #868e96;">ab uni</span>
+                                                                <span style="font-size: 11px; color: #868e96;">{{$user->university_name }}</span>
                                                         </div>
                                                         <div class="single_glance_row mt-1" style="display: flex;">
                                                                 <span class="title" style="font-size:11px; font-weight: 600;">Department :</span>
-                                                                <span style="font-size: 11px; color: #868e96;">ab</span>
+                                                                <span style="font-size: 11px; color: #868e96;">{{$user->department }}</span>
                                                         </div>                                        
                                                     </div>
                                                 </div> 
@@ -877,21 +882,23 @@ tbody, td, tfoot, th, thead, tr {
                                     </div><!--end col-->
                                     <div class="col-md-4 bg-white rounded p-2 ms-4" style="width: 32.4%;">
                                         <div class="row">
+                                           
                                             <div class="col-md-12">
                                                  <h6 style="padding: 13px 10px 0px;">Change password</h6>
                                                 <div class="form-icon position-relative p-2 mt-2">
-                                                    <input type="text" class="form-control" placeholder="Old password" name="" required="">
+                                                    <input type="hidden" name="user_id" value="{{$user->id}}" id="user_id">
+                                                    <input type="password" class="form-control" placeholder="Old password" name="old_password" id="old_password" required="">
                                                 </div>
                                                 <div class="form-icon position-relative p-2">
-                                                    <input type="text" class="form-control" placeholder="New password" name="" required="">
+                                                    <input type="password" class="form-control" placeholder="New password" name="new_password" id="new_password" required="">
                                                 </div>
                                                 <div class="form-icon position-relative p-2">
-                                                    <input type="text" class="form-control" placeholder="Re-type new password" name="" required="">
+                                                    <input type="password" class="form-control" placeholder="Re-type new password" name="new_password_confirmation" id="new_password_confirmation" required="">
                                                     <div class="col-md-12"  style="text-align: center;">
-                                                        <button class="btn btn2 mt-3">Changed</button>
+                                                        <button class="btn btn2 mt-3 change_password">Changed</button>
                                                     </div>
                                                 </div>
-                                            </div>
+                                            </div> 
                                         </div>
                                     </div><!--end col-->
                                     <div class="col-md-2 bg-white rounded p-2 ms-4" style="width:25%;">
@@ -947,6 +954,69 @@ tbody, td, tfoot, th, thead, tr {
       <script src="{{asset('web/js/plugins.init.js')}}"></script>
       <script src="{{asset('web/js/app.js')}}"></script>
       <script src="{{asset('web/css/sweetalert/sweetalert.min.js')}}"></script>
-      <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
+      {{-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> --}}
+
+        {{-- Ajax Form Submit --}}
+    
+        <script src="{{ asset('css/jquery.min.js') }}"></script>
+        <script src="{{ asset('css/jquery-form/dist/jquery.form.min.js') }}"></script>
+        <script src="{{ asset('css/noty/lib/noty.min.js') }}"></script>
+        <script src="{{ asset('css/flatpickr/dist/flatpickr.min.js') }}"></script>
+        <script src="{{ asset('css/wait-me/waitMe.min.js')}}"></script> 
+
+      <script>
+         function pop_up_msg(msg='No message specified', type='success', callback=null){ 
+            new Noty({
+            theme:'sunset',
+            text: msg,
+            type: type,
+            timeout:1500,
+            callbacks:{
+                afterClose: callback
+            }
+            }).show(); 
+        }
+
+        function err_msg(err){
+
+            var msg="Request failed to process, try again later.";
+
+            if(err.responseJSON && err.responseJSON.msg){
+            msg=err.responseJSON.msg;
+            }
+
+            return msg;
+
+        }
+
+
+        $(function(){
+            $('.change_password').on('click', function(){
+                var id =$('#user_id').val();
+                var old_password =$('#old_password').val(); 
+                var new_password =$('#new_password').val();
+                var new_password_confirmation =$('#new_password_confirmation').val();
+
+                var form_data={
+                    _token: "{{ csrf_token() }}",
+                    id: id,
+                    old_password: old_password,
+                    new_password: new_password,
+                    new_password_confirmation: new_password_confirmation,
+                }
+
+                $.post("{{ route('ajax-post', ['name'=>'teacher_change_password']) }}", form_data, function(res){ 
+                    pop_up_msg(res.msg);
+
+                }).fail(function(err){
+
+                    pop_up_msg(err_msg(err), 'error');
+
+                }); 
+            });
+        });
+      </script>
+
+
 </body>
 </html>