public function store() { $data = Input::all(); if (isset($data['phone_number'])) { $data['phone_number'] = str_replace(' ', '', $data['phone_number']); } if (isset($data['work_phone'])) { $data['work_phone'] = str_replace(' ', '', $data['work_phone']); } $u = new User(); $a = false; $role_id = Input::get('role_id'); if ($role_id == Config::get('constants.ROLE_BUYER')) { $a = new Buyer(); $u->status = 2; $data['skip_verification'] = true; } elseif ($role_id == Config::get('constants.ROLE_SELLER')) { $a = new Seller(); } elseif ($role_id == Config::get('constants.ROLE_BROKER')) { $a = new Broker(); } else { //we don't know this role or attempt to register unlisted role unset($data['role_id']); } if (!isset($data['password']) || $data['password'] == "") { $pwd = Str::random(10); $data['password'] = $data['password_confirmation'] = $pwd; } if ($u->validate($data)) { if ($a && $a->validate($data)) { if (isset($pwd)) { Session::set('validate_password', true); } $data['password'] = Hash::make($data['password']); $u->fill($data); $code = Str::random(10); $u->verification_code = $code; $data['verification_code'] = $code; $u->save(); $data['user_id'] = $u->id; $a->fill($data); $a->save(); $email = $u->email; if (isset($data['skip_verification'])) { $data['url']['link'] = url('/'); $data['url']['name'] = 'Go to CompanyExchange'; Mail::queue('emails.templates.welcome', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } else { Mail::queue('emails.templates.progress', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } if ($role_id == Config::get('constants.ROLE_BUYER')) { Auth::loginUsingId($u->id); Alert::success('Welcome to CompanyExchange. Please feel free to browse through our listings and contact sellers you would like to buy from.', 'Congratulations'); return Redirect::to('search?q=')->withSuccess("Welcome {$u->first_name}. Use the form on the left to search for listed businesses or browse the most recent listings below"); } return Redirect::to('login')->withSuccess('Registration successful. Please check email to activate your account'); } Input::flash(); return View::make('users.register')->withErrors($a ? $a->getValidator() : []); } Input::flash(); return View::make('users.register')->withErrors($u->getValidator()); }
public function validate($input = null, $rules = null, $messages = null) { if (is_null($input)) { $input = Input::all(); } if (is_null($rules)) { $rules = $this->getRules(); } if (is_null($messages)) { $messages = $this->getMessages(); } $v = Validator::make($input, $rules, $messages); if ($v->passes()) { return true; } else { Input::flash(); foreach ($input as $key => $value) { $error = $v->messages()->get($key); if ($error) { $this->validationMessages[$key] = $error; } } $this->error = $v->errors(); return false; } }
public function postGroupUpdate() { $id = Input::get('id'); $group = Group::find($id); if (!$group) { return Redirect::action('Ideaterminal\\Transdb\\Controllers\\TransdbController@getGroup'); } $validator = Validator::make(Input::all(), array('name' => "required|alphanum|unique:transdb_groups,name,{$id}")); if ($validator->fails()) { Input::flash(); return Redirect::action('Ideaterminal\\Transdb\\Controllers\\TransdbController@getGroupUpdate', array($id))->withErrors($validator); } else { $group->name = Input::get('name'); $group->save(); $this->layout->content = View::make('transdb::groupupdate')->with('group', $group)->with('success', 'Group successfully updated.'); } }
private function registerUser($data, $role) { if (isset($data['phone_number'])) { $data['phone_number'] = str_replace(' ', '', $data['phone_number']); } if (isset($data['work_phone'])) { $data['work_phone'] = str_replace(' ', '', $data['work_phone']); } $u = new User(); $data['role_id'] = $role; switch (strtolower($role)) { case Config::get('constants.ROLE_SELLER'): $a = new Seller(); break; case Config::get('constants.ROLE_BROKER'): $a = new Broker(); break; default: $a = new Buyer(); $u->status = 2; $data['skip_verification'] = true; break; } if (!isset($data['password']) || $data['password'] == "") { $pwd = Str::random(10); $data['password'] = $data['password_confirmation'] = $pwd; } if ($u->validate($data)) { if ($a->validate($data)) { if (isset($pwd)) { Session::set('validate_password', true); } $data['password'] = Hash::make($data['password']); $u->fill($data); $code = Str::random(10); $u->verification_code = $code; $data['verification_code'] = $code; $u->save(); $data['user_id'] = $u->id; $a->fill($data); $a->save(); $email = $u->email; if (isset($data['skip_verification'])) { $data['url']['link'] = url('/'); $data['url']['name'] = 'Go to CompanyExchange'; Mail::queue('emails.templates.welcome', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } else { Mail::queue('emails.templates.progress', $data, function ($message) use($email) { $message->from('*****@*****.**', 'CompanyExchange'); $message->to($email); $message->subject('Welcome to CompanyExchange'); }); } Auth::loginUsingId($u->id); return true; } Input::flash(); return $a->getValidator(); } Input::flash(); return $u->getValidator(); }
/** * Validate the model instance * * @param array $rules Validation rules * @param array $customMessages Custom error messages * @return bool * @throws InvalidModelException */ public function validate(array $rules = array(), array $customMessages = array()) { if ($this->fireModelEvent('validating') === false) { if ($this->throwOnValidation) { throw new InvalidModelException($this); } else { return false; } } // check for overrides, then remove any empty rules $rules = empty($rules) ? static::$rules : $rules; foreach ($rules as $field => $rls) { if ($rls == '') { unset($rules[$field]); } } if (empty($rules)) { $success = true; } else { $customMessages = empty($customMessages) ? static::$customMessages : $customMessages; if ($this->forceEntityHydrationFromInput || empty($this->attributes) && $this->autoHydrateEntityFromInput) { $this->fill(Input::all()); } $data = $this->getAttributes(); // the data under validation // perform validation $validator = static::makeValidator($data, $rules, $customMessages); $success = $validator->passes(); if ($success) { // if the model is valid, unset old errors if ($this->validationErrors->count() > 0) { $this->validationErrors = new MessageBag(); } } else { // otherwise set the new ones $this->validationErrors = $validator->messages(); // stash the input to the current session if (!self::$externalValidator && Input::hasSession()) { Input::flash(); } } } $this->fireModelEvent('validated', false); if (!$success && $this->throwOnValidation) { throw new InvalidModelException($this); } return $success; }
/** * Display a listing of the resource. * * @return Response */ public function postCategory(Request $request) { Input::flash(); $detail = Input::get('detail'); $staff_options = Staff::select('Id', DB::raw('CONCAT(first_name, " ", last_name) AS full_name'))->orderBy('first_name')->lists('full_name', 'Id')->toArray(); $posts = Post::with(array('departments' => function ($query) { $query->addSelect(array('name')); }))->with(array('staffs' => function ($query) { $query->addSelect(array(DB::raw("concat(staff.first_name, ' ', staff.last_name) as `name`"))); })); if (Input::has('media_mention')) { $posts = $posts->mediamention(); } if (Input::has('presentation')) { $posts = $posts->presentation(); } if (Input::has('meeting')) { $posts = $posts->meeting(); } if (Input::has('testimonial')) { $posts = $posts->testimonial(); } if (Input::has('sponsored_event')) { $posts = $posts->sponsoredevent(); } if (Input::has('on_campus_collaboration')) { $posts = $posts->orWhere('on_campus_collaboration', 1); } if (Input::has('off_campus_collaboration')) { $posts = $posts->offcampuscollaboration(); } if (Input::has('achievement')) { $posts = $posts->achievement(); } if (Input::has('satifaction_survey')) { $posts = $posts->satifactionsurvey(); } if (Input::has('other')) { $posts = $posts->orWhere('other', 1); } if (Input::has('staff')) { if (Input::get('staff') != 0) { $posts = $posts->whereHas('staffs', function ($query) { $query->where('id', '=', Input::get('staff')); }); } } if (Input::has('publish_date_from') || Input::has('publish_date_to')) { $from = date('Y-m-d', strtotime(Input::get('publish_date_from'))); if (Input::has('publish_date_to')) { $to = date('Y-m-d', strtotime(Input::get('publish_date_to'))); } else { $to = date('Y-m-d', strtotime(Carbon::now())); } $posts = $posts->whereBetween('publish_date', array($from, $to)); } $posts = $posts->get(); //dd($posts); /*$posts = $posts->with(['departments' => function($query) { $query->select('name'); }])->get();*/ // I do this mapping to flatten the nested arrays // $posts = array_map(function($val) // { // return array_dot($val); // }, $posts); $action = Input::get('action', 'none'); if ($action == 'query') { return view('posts.report_category', compact('posts', 'staff_options', 'detail'))->withInput(Input::all()); } else { if ($action == 'excel') { if ($detail == 1) { Excel::create('Export', function ($excel) use($posts) { $excel->sheet('Data', function ($sheet) use($posts) { //$sheet->fromArray($posts); $sheet->loadView('posts.category_full')->with('posts', $posts); }); })->export('xls'); } else { Excel::create('Export', function ($excel) use($posts) { $excel->sheet('Data', function ($sheet) use($posts) { //$sheet->fromArray($posts); $sheet->loadView('posts.category')->with('posts', $posts); }); })->export('xls'); } } } /* Excel::create('posts', function($excel) use($posts) { $excel->sheet('Category', function($sheet) use($posts) { $sheet->fromArray($posts); }); })->export('xls'); */ }
/** * Validate the model instance * * @param array $rules Validation rules * @param array $customMessages Custom error messages * @return bool */ public function validate(array $rules = array(), array $customMessages = array()) { // check for overrides, then remove any empty rules $rules = empty($rules) ? static::$rules : $rules; foreach ($rules as $field => $rls) { if ($rls == '') { unset($rules[$field]); } } if (empty($rules)) { return true; } $customMessages = empty($customMessages) ? static::$customMessages : $customMessages; if ($this->forceEntityHydrationFromInput || empty($this->attributes) && $this->autoHydrateEntityFromInput) { // pluck only the fields which are defined in the validation rule-set $attributes = array_intersect_key(Input::all(), $rules); //Set each given attribute on the model foreach ($attributes as $key => $value) { $this->setAttribute($key, $value); } } $data = $this->attributes; // the data under validation // perform validation $validator = Validator::make($data, $rules, $customMessages); $success = $validator->passes(); if ($success) { // if the model is valid, unset old errors if ($this->validationErrors->count() > 0) { $this->validationErrors = new MessageBag(); } } else { // otherwise set the new ones $this->validationErrors = $validator->messages(); // stash the input to the current session if (Input::hasSessionStore()) { Input::flash(); } } return $success; }
public function store() { $input = Input::all(); Input::flash(); if (isset($input['id']) && $input['id'] != '') { $input = Input::all(); $rules = array('id' => array('required'), 'email' => 'required|email'); $useredit = Sentry::findUserById($input['id']); if ($input['password'] != '') { $rules['password'] = array('required', 'min:6'); $rules['retype_password'] = array('required', 'min:6'); } $validation = Validator::make(Input::all(), $rules); //check email if ($validation->fails()) { $message = ''; $mess = $validation->errors()->getMessages(); foreach ($mess as $v) { $message .= $v[0] . ' '; } if ($message != '') { Session::flash('message', $message); } if (!isset($input['id'])) { return Redirect::to('manager/users'); } return Redirect::to('manager/users/edit/' . $input['id']); } else { try { $useredit->email = $input['email']; $useredit->first_name = isset($input['first_name']) ? $input['first_name'] : ''; $useredit->last_name = isset($input['last_name']) ? $input['last_name'] : ''; if ($input['password'] != '') { $useredit->password = $input['password']; } if ($useredit->save()) { $groupscursor = $useredit->getGroups(); $groups = array(); $inputgroups = isset($input['groups']) ? $input['groups'] : array(); foreach ($groupscursor as $v) { if (!in_array($v['id'], $inputgroups)) { $g = Sentry::findGroupById($v['id']); $useredit->removeGroup($g); } $groups[] = $v['id']; } if (isset($input['groups'])) { foreach ($input['groups'] as $v) { if (!in_array($v, $groups)) { $Group = Sentry::findGroupById($v); $useredit->addGroup($Group); } } } } Session::flash('message', trans('saved')); return Redirect::to('manager/users'); } catch (LoginRequiredException $e) { Session::flash('message', 'Login field is required.'); return Redirect::to('manager/users/edit/' . $input['id']); } catch (PasswordRequiredException $e) { Session::flash('message', 'Password field is required.'); return Redirect::to('manager/users/edit/' . $input['id']); } catch (UserExistsException $e) { Session::flash('message', 'User with this login already exists.'); return Redirect::to('manager/users/edit/' . $input['id']); } catch (GroupNotFoundException $e) { Session::flash('message', 'Group was not found.'); return Redirect::to('manager/users/edit/' . $input['id']); } } } else { $rules = array('password' => array('required', 'min:6'), 'retype_password' => array('required', 'min:6'), 'email' => 'required|email'); $validation = Validator::make(Input::all(), $rules); //check $objUsers = new Users(); $check = $objUsers->where('email', '=', trim(strtolower($input['email'])))->count(); if ($validation->fails() || $check > 0) { $messages = ''; if ($check > 0) { $messages .= 'User with this email already exists. '; } $mess = $validation->errors()->getMessages(); foreach ($mess as $v) { $messages .= $v[0] . ' '; } if ($messages != '') { Session::flash('message', $messages); } return Redirect::to('manager/users/edit'); } else { try { $datacreateUser = array('email' => trim(strtolower($input['email'])), 'password' => isset($input['password']) ? $input['password'] : '', 'activated' => true, 'first_name' => isset($input['first_name']) ? $input['first_name'] : '', 'last_name' => isset($input['last_name']) ? $input['last_name'] : ''); $user = Sentry::createUser($datacreateUser); /*$email = trim(strtolower($input['email'])); $first_name = trim(strtolower($input['first_name']));*/ if (isset($input['groups']) && isset($user['id'])) { foreach ($input['groups'] as $v) { $Group = Sentry::findGroupById($v); $user->addGroup($Group); } } /*Mail::send('system::email.email_template.acount_info', $input, function($message) use ($email, $first_name) { $message->to($email, $first_name)->subject('Welcome to the Tastable.net'); });*/ } catch (LoginRequiredException $e) { Session::flash('message', 'Login field is required. '); return Redirect::to('manager/users/edit'); } catch (PasswordRequiredException $e) { Session::flash('message', 'Password field is required. '); return Redirect::to('manager/users/edit'); } catch (UserExistsException $e) { Session::flash('message', 'User with this email already exists. '); return Redirect::to('manager/users/edit'); } catch (GroupNotFoundException $e) { Session::flash('message', 'Group was not found.'); return Redirect::to('manager/users/edit'); } } Session::flash('message', 'User created'); return Redirect::to('manager/users'); } }
/** * Update the specified resource in storage. * PUT /listings/{id} * * @param int $id * @return Response */ public function update($listing) { $data = Input::all(); //unset all empty control foreach ($data as $key => $value) { if ($value == "") { unset($data[$key]); } } if ($listing->validate($data, 'update')) { $listing->update($data); $listingCount = 0; //delete ignored photos $photosKept = isset($data['photos_kept']) ? $data['photos_kept'] : []; foreach ($listing->photos as $photo) { if (!in_array($photo->id, $photosKept)) { $photo->delete(); } else { $listingCount++; } } $files = Input::file('photos'); //upload new photos foreach ($files as $file) { if ($file != null && $file->isValid()) { $lp = new ListingPhoto(); $lp->photo_url = 'listings/' . $listing->id . '/' . time() . $file->getClientOriginalName(); $file->move(public_path('files/listings/' . $listing->id), $lp->photo_url); $lp->listing()->associate($listing); $lp->save(); $listingCount++; } } if ($listingCount < 3) { $success = '<strong>Upload more photos to improve your listing.</strong>'; } else { $a = false; //lol, just for conditional return } Alert::success('Your listing has been updated successfully', 'Congratulations'); return View::make(Auth::user()->role->name . '.listings.edit')->with(compact('listing', isset($success) ? 'success' : 'a')); } Input::flash(); return View::make(Auth::user()->role->name . '.listings.edit')->withErrors($listing->getValidator()); }
/** * Change the user password * * @param int $id * @return Response */ public function changePassword($id) { //Check permission if (Permissions::isAllowed(Auth::user(), 'user', 'update') !== true) { return Redirect::route('get admin/login')->with('reason', Lang::get('firadmin::admin.messages.insufficient-permission') . '<br>')->with('error', 1); } //Get the user in database $user = $this->_users->find($id); //If the user don't exist if (!$user) { //Returns a response in JSON format if it's an Ajax request if (AjaxRequest::isAjax()) { return Response::json(array('error' => 1, 'reason' => Lang::get('firadmin::admin.messages.user-not-found'))); } //Redirect to user index with error return Redirect::to(Config::get('firadmin::route.user'))->with('reason', Lang::get('firadmin::admin.messages.user-not-found'))->with('error', 1); // Else, great the user exist !!! } else { //Define custom validation rules because we don't want to validate same field then user store $rules = array('password' => 'required|min:5', 'password_confirmation' => 'required|min:5|same:password'); //Update user $user->password = Input::get('password'); $user->password_confirmation = Input::get('password_confirmation'); //Try to save the user if ($user->save($rules)) { //Returns a response in JSON format if it's an Ajax request if (AjaxRequest::isAjax()) { return Response::json(array('success' => Lang::get('firadmin::admin.update-password-success'))); } //Redirect to user index with success message return Redirect::to(Config::get('firadmin::route.user'))->with('success', Lang::get('firadmin::admin.update-password-success')); //Else, save validation fail } else { //Flash input to repopulate them in the form Input::flash(); //Returns a response in JSON format if it's an Ajax request if (AjaxRequest::isAjax()) { return Response::json(array('error' => 1, 'reason' => $user->errors()->all(':message'))); } //Redirect to the form with errors return Redirect::to(Config::get('firadmin::route.user') . '/' . $id . '/edit#change-password')->with('reason', $user->errors()->all(':message<br>'))->with('error', 1); } } }
/** * Updates an article * @param Article $article Article to update * @return Response */ public function updateArticle($article) { $data = Input::all(); if ($article->validate($data)) { $article->update($data); return View::make('admin.articles.edit')->withArticle($article)->withSuccess('<strong>Article updated successfully.</strong>'); } Input::flash(); return View::make('admin.articles.edit')->withArticle($article)->withErrors($article->getValidator()); }
/** * Update the specified resource in storage. * PUT /adverts/{id} * * @param int $id * @return Response */ public function update($advert) { $data = Input::all(); //unset all empty control foreach ($data as $key => $value) { if ($value == "") { unset($data[$key]); } } if ($advert->validate($data, 'update')) { $advert->update($data); $success = 'Your advert has been updated successfully.'; Alert::success($success, 'Congratulations'); return View::make(Auth::user()->role->name . '.adverts.edit')->with(compact('advert', isset($success) ? 'success' : 'a')); } Input::flash(); return View::make(Auth::user()->role->name . '.adverts.edit')->withErrors($advert->getValidator()); }