/**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     if (SiteConstants::isManager($data["user_type"])) {
         $userType = BasicSiteRepository::getManagerTypes()[$data["managerType"]];
         return User::create(['username' => $data['username'], 'password' => $data['password'], 'active' => 0, 'user_type' => $userType, 'management_level' => $data['management_level'], 'sport_type' => $data['sport_type'], 'profile_image_path' => $data['profile_image_path'], 'confirmation_token' => bcrypt(time())]);
     } else {
         if (SiteConstants::isTalent($data["user_type"])) {
             return User::create(['username' => $data['username'], 'password' => $data['password'], 'active' => 0, 'user_type' => $data['user_type'], 'management_level' => $data['management_level'], 'sport_type' => $data['sport_type'], 'profile_image_path' => $data['profile_image_path'], 'confirmation_token' => bcrypt(time())]);
         }
     }
 }
 /**
  * Retrieves ManagerProfile Model, and send back to the client
  * @return JSON result
  */
 public function getProfileData()
 {
     $manager = [];
     try {
         $manager = ManagerProfile::where('user_id', '=', session(SiteSessions::USER_ID))->firstOrFail();
         $manager = $manager->toArray();
         $manager_additional_info = User::find(session(SiteSessions::USER_ID));
         //Selecting Required Fields from User table
         $manager = array_merge($manager, ["user_type" => $manager_additional_info->user_type, "sport_type" => $manager_additional_info->sport_type, "management_level" => $manager_additional_info->management_level, "profile_image_path" => $manager_additional_info->profile_image_path]);
     } catch (ModelNotFoundException $e) {
         $this->error_message = "Manager not found";
         $this->updateRequestStatus(RequestStatusEnum::MODEL_NOT_FOUND);
     }
     return $this->sendResponse($manager);
 }
Esempio n. 3
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 public function create(array $data)
 {
     if (SiteConstants::isManager($data["user_type"])) {
         $userType = BasicSiteRepository::getManagerTypes()[$data["managerType"]];
         $user = null;
         $user = DB::transaction(function () use($data, $user, $userType) {
             $user = User::create(['username' => $data['username'], 'password' => $data['password'], 'active' => 0, 'user_type' => $userType, 'management_level' => $data['management_level'], 'sport_type' => $data['sport_type'], 'profile_image_path' => $data['profile_image_path'], 'confirmation_token' => bcrypt(time())]);
             $user->managerProfile()->create(['first_name' => '', 'middle_name' => '', 'last_name' => '']);
             return $user;
         });
         return $user;
     } else {
         if (SiteConstants::isTalent($data["user_type"])) {
             return User::create(['username' => $data['username'], 'password' => $data['password'], 'active' => 0, 'user_type' => $data['user_type'], 'management_level' => $data['management_level'], 'sport_type' => $data['sport_type'], 'profile_image_path' => $data['profile_image_path'], 'confirmation_token' => bcrypt(time())]);
         }
     }
 }
 /**
  * Updating Email or Password of a user as per selected choice of a user
  * @param Request $request
  */
 public function updateGeneralSettings(Request $request)
 {
     $settingType = $request->has("setting_type") ? $request->get("setting_type") : null;
     if ($settingType == null) {
         return redirect()->back()->withErrors(['Setting Type not specified by the user.']);
     }
     switch ($settingType) {
         case UserSettings::GENERAL_TYPE_EMAIL:
             $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users,username']);
             if ($validator->fails()) {
                 return redirect()->back()->with(['setting_type' => UserSettings::GENERAL_TYPE_EMAIL])->withErrors($validator->errors());
             }
             $userProfile = User::find(Session::get(SiteSessions::USER_ID));
             $userProfile->username = $request->get("email");
             $userProfile->save();
             return redirect('settings/general')->with(["setting_type" => UserSettings::GENERAL_TYPE_EMAIL, "general_update_status" => "successful"]);
             break;
         case UserSettings::GENERAL_TYPE_PASSWORD:
             $validator = Validator::make($request->all(), ['password' => 'required|confirmed|min:6']);
             if ($validator->fails()) {
                 return redirect()->back()->with(['setting_type' => UserSettings::GENERAL_TYPE_PASSWORD])->withErrors($validator->errors());
             }
             $userProfile = User::find(Session::get(SiteSessions::USER_ID));
             $userProfile->password = $request->get("password");
             $userProfile->save();
             return redirect('settings/general')->with(["setting_type" => UserSettings::GENERAL_TYPE_PASSWORD, "general_update_status" => "successful"]);
             break;
     }
     return redirect('settings/general')->with(["general_update_status" => "error"]);
 }
 /**
  * Contacting Manager by Talent
  * @param Request $request
  */
 public function contactManager(Request $request)
 {
     $validator = Validator::make($request->all(), ['manager_id' => 'required', 'talent_id' => 'required', 'message' => 'required']);
     if ($validator->fails()) {
         return response()->json(['status' => 'error', 'error_type' => 'ID_MISSING']);
     }
     if (Session::get(SiteSessions::USER_ID) != $request->talent_id) {
         return response()->json(['status' => 'error', 'error_type' => 'TALENT_ID_INVALID']);
     }
     try {
         $user = User::find(Session::get(SiteSessions::USER_ID));
         $manager = ManagersDatabase::find($request->manager_id);
         Event::fire(new SendMail(SendMail::MAIL_TYPE_CONTACT_MANAGER, $manager->email, [], ["manager" => $manager, "talent" => $user, "message" => $request->message]));
         DB::table('managers_contacted')->insert(['user_id' => $request->talent_id, 'manager_id' => $request->manager_id, 'message_to_manager' => $request->message, 'contacted_on' => Carbon::now()]);
     } catch (QueryException $e) {
         return response()->json(['status' => 'error', 'error_type' => 'DATABASE_ERROR']);
     }
     return response()->json(['status' => 'successful']);
 }
 /**
  *Resending confirmation link to the User
  */
 public function resendConfirmationLink()
 {
     $user = User::find(Session::get(SiteSessions::USER_ID));
     $user->confirmation_token = bcrypt(time());
     $user->save();
     Event::fire(new SendMail(SendMail::MAIL_TYPE_USER_CONFIRMATION, $user->username, [], $user));
     Session::flash("resent_confirmation_link", 'successful');
     return redirect('account-not-confirmed');
 }