Ejemplo n.º 1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $is_student = Auth::user()->is_student;
     $color = $is_student ? '#3498db' : '#e74c3c';
     if ($is_student) {
         logger("学生アカウントナリ");
         $user = UserProfile::where('student_id', '=', Auth::user()->id)->first();
         if ($user === null) {
             // 学生用ページを表示
             $tech_items = ['Java' => 0, 'C' => 0, 'C++' => 0, 'Python' => 0, 'C#' => 0, 'Objective-C' => 0, 'Perl' => 0, 'HTML' => 0, 'CSS' => 0, 'JavaScript' => 0, 'PHP' => 0, 'Ruby' => 0, 'Scala' => 0];
             $tech = json_encode($tech_items);
             $user = ["name" => "", "student_id" => Auth::user()->id, "gender" => "", "birth" => "", "address" => "", "phone_number" => "", "collage" => "", "collage_type" => "", "github" => "", "intern" => "", "hackathon" => "", "work" => "", "tech" => $tech];
             UserProfile::create($user);
         }
         $data = ['名前' => Auth::user()->name, '性別' => $user['gender'] === "man" ? "男" : "女", '誕生日' => $user['birth'], '住所' => $user['address'], "メールアドレス" => Auth::user()->email, '電話番号' => $user['phone_number'], '大学名' => $user['collage'], '学部' => $user['collage_type'], 'Github' => $user['github']];
         $tech = json_decode($user['tech'], true);
         $award = ['インターン' => $user['intern'], 'ハッカソン' => $user['hackathon'], '仕事' => $user['work']];
         return view('mypage', ["datas" => $data, "color" => $color, "awards" => $award, "tech" => $tech]);
     } else {
         logger("企業アカウントナリ");
         // 企業用ページを表示
         $profile = CompanyProfile::where('company_id', '=', Auth::user()->id)->first();
         logger($profile);
         if ($profile === null) {
             logger("新規作成するナリ");
             $profile = ['name' => "", 'company_id' => Auth::user()->id, 'phone_number' => "", 'email' => "", 'homepage' => ""];
             CompanyProfile::create($profile);
         }
         $works = Post::where('company_id', '=', Auth::user()->id)->get();
         logger($profile);
         return view('mypage_company', ['profile' => $profile, 'works' => $works, 'color' => $color]);
     }
 }
 /**
  * Run the users seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users_profiles')->delete();
     $statement = "ALTER TABLE users_profiles AUTO_INCREMENT = 1;";
     DB::unprepared($statement);
     UserProfile::create(['firstname' => 'Alexandre', 'lastname' => 'Mangin', 'phone' => '0616391876', 'user_id' => 1]);
     UserProfile::create(['firstname' => 'Alan', 'lastname' => 'Corbel', 'phone' => '0626381876', 'user_id' => 2]);
     UserProfile::create(['firstname' => 'Christophe', 'lastname' => 'Larquey', 'phone' => '0605040302', 'user_id' => 3]);
 }
 /**
  * @param RegisterRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postRegister(RegisterRequest $request)
 {
     $regData = ['name' => $request->name, 'email' => $request->email, 'password' => $request->password];
     //Use native auth login because do not need to check status when registering
     //        auth()->login($user = $this->auth->create($regData));
     //        if (config('access.users.confirm_email')) {
     if ($user = $this->auth->create($regData)) {
         auth()->login($user);
         $userData = ['address' => $request->address, 'date_of_birth' => $request->dob, 'phone' => $request->phone, 'gender' => $request->gender, 'next_of_kin_relationship' => $request->kin_rel, 'next_of_kin_address' => $request->kin_address, 'next_of_kin_gender' => $request->kin_gender, 'next_of_kin_phone' => $request->kin_number, 'next_of_kin_name' => $request->kin_name, 'user_id' => auth()->user()->id];
         $userProfile = new UserProfile();
         if ($userProfile->create($userData)) {
             return redirect('dashboard');
         } else {
             return redirect()->back()->withErrors('An Error Occurred');
         }
     }
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return UserProfile::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
 public function saveProfile(Request $request)
 {
     if (Auth::check()) {
         $rules1 = ['name' => 'required|max:100', 'country' => 'required|max:20', 'city' => 'required|max:20 ', 'phone' => 'required|regex:/^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$/', 'description' => 'required|max:200'];
         $rules2 = ['name' => 'max:100', 'country' => 'max:20|min:2', 'city' => 'max:20 |min:2', 'phone' => 'regex:/^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$/', 'description' => 'max:200'];
         $validator1 = Validator::make($request->input(), $rules1);
         $validator2 = Validator::make($request->input(), $rules2);
         if ($this->userProfile != null) {
             if ($validator2->passes()) {
                 if ($request->hasFile('image')) {
                     if ($request->file('image')->isValid()) {
                         $destPath = '/home/vagrant/Code/Project/LaravelProject/public/storage/uploads/' . Auth::id();
                         // upload path
                         $extension = $request->file('image')->getClientOriginalExtension();
                         $fileName = date('Y_m_d_H_i_s') . '_' . rand(1, 9999) . '.' . $extension;
                         // renameing image
                         $request->file('image')->move($destPath, $fileName);
                         $this->userProfile->portrait = 'storage/uploads/' . Auth::id() . '/' . $fileName;
                     }
                 }
                 if ($request->input('name') != "") {
                     $this->userProfile->user->name = $request->input('name');
                     $this->userProfile->user->save();
                 }
                 if ($request->input('gender') != "") {
                     $this->userProfile->gender = $request->input('gender');
                 }
                 if ($request->input('country') != "") {
                     $this->userProfile->country = $request->input('country');
                 }
                 if ($request->input('city') != "") {
                     $this->userProfile->city = $request->input('city');
                 }
                 if ($request->input('phone') != "") {
                     $this->userProfile->phone = $request->input('phone');
                 }
                 if ($request->input('description') != "") {
                     $this->userProfile->description = $request->input('description');
                 }
                 $this->userProfile->save();
             } else {
                 return "Hello!!1";
                 return redirect('/profile')->withInput()->withErrors($validator2);
             }
         } else {
             if ($validator1->passes()) {
                 $destPath = "";
                 $fileName = "";
                 if ($request->hasFile('image')) {
                     if ($request->file('image')->isValid()) {
                         $destPath = '/home/vagrant/Code/Project/LaravelProject/public/storage/uploads/' . Auth::id();
                         // upload path
                         $extension = $request->file('image')->getClientOriginalExtension();
                         $fileName = date('Y_m_d_H_i_s') . '_' . rand(1, 9999) . '.' . $extension;
                         // renameing image
                         $request->file('image')->move($destPath, $fileName);
                     }
                 }
                 UserProfile::create(['user_id' => Auth::id(), 'phone' => $request->input('phone'), 'gender' => $request->input('gender'), 'city' => $request->input('city'), 'country' => $request->input('country'), 'description' => $request->input('description'), 'portrait' => 'storage/uploads/' . Auth::id() . '/' . $fileName]);
                 $this->userProfile = UserProfile::where('user_id', Auth::id())->get()->first();
                 $this->userProfile->description = $request->input('description');
                 $this->userProfile->portrait = 'storage/uploads/' . Auth::id() . '/' . $fileName;
                 $this->userProfile->save();
                 $user = User::where('id', Auth::id())->get()->first();
                 $user->name = $request->input('name') == "" ? $user->name : $request->input('name');
             } else {
                 return redirect('/profile')->withInput()->withErrors($validator1);
             }
         }
         return redirect()->action('SelfMainpageController@showProfile');
     }
 }