public function post_registration() { $post = array(); $post['inputCid'] = Input::get('inputCid'); $post['inputVaName'] = Input::get('inputVaName'); $post['inputVaStartDate'] = Input::get('inputVaStartDate'); $post['inputUrl'] = Input::get('inputUrl'); $post['inputDescription'] = Input::get('inputDescription'); $post['inputVatsimImagePageLink'] = Input::get('inputVatsimImagePageLink'); $post['inputCountry'] = Input::get('inputCountry'); $post['inputName'] = Input::get('inputName'); $post['inputEmail'] = Input::get('inputEmail'); $post['inputPassword'] = Input::get('inputPassword'); $post['inputPassword_confirmation'] = Input::get('inputPassword_confirmation'); $post['inputCategory'] = Input::get('inputCategory'); $post['inputCopyVARoster'] = Input::get('inputCopyVARoster'); // Laravel gets mad and throws an error if category isn't defined so let's go ahead and just define it but leave it empty. if (empty($post['inputCategory'])) { $post['inputCategory'] = ''; } // Format our URL field with the http before if it isn't there already if (!strpos($post['inputUrl'], 'http://') and !strpos($post['inputUrl'], 'https://')) { $post['inputUrl'] = 'http://' . $post['inputUrl']; } // Start our validator if (Input::hasFile('inputUploadVARoster')) { $validator = Validator::make(array('Cid' => $post['inputCid'], 'Va Name' => $post['inputVaName'], 'Va Start Date' => $post['inputVaStartDate'], 'Url' => $post['inputUrl'], 'Description' => $post['inputDescription'], 'Vatsim Image Page Link' => $post['inputVatsimImagePageLink'], 'Country' => $post['inputCountry'], 'Name' => $post['inputName'], 'Email' => $post['inputEmail'], 'Password' => $post['inputPassword'], 'Password_confirmation' => $post['inputPassword_confirmation'], 'Category' => $post['inputCategory']), array('Cid' => 'required|integer|unique:vas,cid', 'Va Name' => 'required', 'Va Start Date' => 'required|date_format:"j F, Y"', 'Url' => 'required|url', 'Description' => 'required|max:200', 'Vatsim Image Page Link' => 'required|url', 'Country' => 'required', 'Name' => 'required', 'Email' => 'required|email|unique:vas,email', 'Password' => 'required|min:6|confirmed', 'Password_confirmation' => 'required|min:6', 'Category' => 'required|max:' . Setting::fetch('max_categories')), array('Category.max' => 'You have selected more than :max categories.', 'Cid.unique' => 'There is already an account with an active virtual airline with that CID.')); } else { $validator = Validator::make(array('Cid' => $post['inputCid'], 'Va Name' => $post['inputVaName'], 'Va Start Date' => $post['inputVaStartDate'], 'Url' => $post['inputUrl'], 'Description' => $post['inputDescription'], 'Vatsim Image Page Link' => $post['inputVatsimImagePageLink'], 'Country' => $post['inputCountry'], 'Name' => $post['inputName'], 'Email' => $post['inputEmail'], 'Password' => $post['inputPassword'], 'Password_confirmation' => $post['inputPassword_confirmation'], 'Category' => $post['inputCategory'], 'Roster' => $post['inputCopyVARoster']), array('Cid' => 'required|integer|unique:vas,cid', 'Va Name' => 'required', 'Va Start Date' => 'required|date_format:"j F, Y"', 'Url' => 'required|url', 'Description' => 'required|max:200', 'Vatsim Image Page Link' => 'required|url', 'Country' => 'required', 'Name' => 'required', 'Email' => 'required|email|unique:vas,email', 'Password' => 'required|min:6|confirmed', 'Password_confirmation' => 'required|min:6', 'Category' => 'required|max:' . Setting::fetch('max_categories'), 'Roster' => 'required'), array('Category.max' => 'You have selected more than :max categories.', 'Cid.unique' => 'There is already an account with an active virtual airline with that CID.', 'Roster.required' => 'Please either upload a file containing your roster or copy and paste the roster.')); } if ($validator->fails()) { // The given data did not pass validation $messages = $validator->messages(); $errorStr = ''; foreach ($messages->all('<li>:message</li>') as $message) { $errorStr .= '<div class="alert alert-error">' . $message . '</div>'; } echo $errorStr; } else { //Check to see if the member submitted a file, if so let's get that uploaded and moved to the appropriate place if (Input::hasFile('inputUploadVARoster')) { $file = Input::file('inputUploadVARoster'); //Create an array of acceptable mime types $mimetypes = array('text/plain', 'application/msword', 'application/zip', 'text/rtf', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //Create an array of acceptable file extensions $fileextentions = array('txt', 'rtf', 'doc', 'docx', 'csv', 'xls', 'xlsx'); if (!in_array($file->getMimeType(), $mimetypes)) { echo '<div class="alert alert-error">The roster file you have uploaded does not appear to be an acceptable file type.</div>'; die; } if (!in_array($file->getClientOriginalExtension(), $fileextentions)) { echo '<div class="alert alert-error">The roster file you have uploaded does not appear to have a valid file extension.</div>'; die; } //Alright looks like this is an acceptable file. $destination_path = public_path() . Setting::fetch('roster_directory'); $fileName = sha1($post['inputCid'] . time()) . $post['inputCid'] . '.' . $file->getClientOriginalExtension(); $file->move($destination_path, $fileName); } if (Category::isHiddenCategory($post['inputCategory'])) { echo '<div class="alert alert-error">You are not authorized to use that category.</div>'; die; } //Submit Data //Create an instance of our model $vas = new User(); //Map our fields $vas->cid = $post['inputCid']; //Hash our password $vas->password = Hash::make($post['inputPassword']); $vas->vaname = $post['inputVaName']; $vas->startdate = $post['inputVaStartDate']; $vas->url = $post['inputUrl']; $vas->description = $post['inputDescription']; $vas->vatsimimagepagelink = $post['inputVatsimImagePageLink']; $vas->country = $post['inputCountry']; $vas->name = $post['inputName']; $vas->email = $post['inputEmail']; $vas->categories = implode(",", $post['inputCategory']) . ','; //All VAs must be approved first so the default status will be 0 for unapproved or not active. $vas->status = '0'; if (!Input::hasFile('inputUploadVARoster')) { $vas->rosterdata = nl2br($post['inputCopyVARoster']); } else { $vas->rosterfile = $fileName; } //Save our data $vas->save(); //Great, now let's send our welcome email to the member $template = SystemEmailTemplate::find('registration_received'); $subject = $template->subject; $email = $post['inputEmail']; $content = EmailTemplate::replaceContent($template->content, $post['inputCid']); //Send our email $data = array('name' => $post['inputName'], 'email' => $email, 'subject' => $subject); //Alright. Time to do some email sending. Mail::send('email.default', array("content" => $content), function ($message) use($data) { $message->to($data['email'], $data['name'])->subject($data['subject']); }); } }
public function post_vapubliccategoriessave() { $cid = Input::get('cid'); $user = User::findOrFail($cid); $categories = Input::get('categories'); if (empty($categories)) { $categories = ''; } //F**k it. Let's just start the validator $validator = Validator::make(array('categories' => $categories), array('categories' => 'max: ' . Setting::fetch('max_categories')), array('categories.max' => 'You have selected more than :max categories.')); if ($validator->fails()) { // The given data did not pass validation $messages = $validator->messages(); $errorStr = ''; foreach ($messages->all('<li>:message</li>') as $message) { $errorStr .= $message; } return Redirect::to('console/va/' . $cid . '#categories')->with('message', $errorStr); } //We need to check and see if any hidden categories are currently included in the categories string and add them to our new string if so $currentCategories = explode(',', $user->categories); array_pop($currentCategories); //Get a list of hidden categories $appendlist = ''; foreach ($currentCategories as $currentCategory) { if (Category::isHiddenCategory($currentCategory)) { $appendlist .= $currentCategory . ','; } } $categories = implode(',', $categories); $categories .= ',' . $appendlist; $user->categories = $categories; $user->save(); return Redirect::to('console/va/' . $cid . '#categories')->with('message', 'Public Categories Saved Successfully.'); }