public function dologin() { $rules = array('username' => 'required', 'password' => 'required'); $message = array('required' => 'Data :attribute harus diisi', 'min' => 'Data :attribute minimal diisi :min karakter'); $validator = Validator::make(Input::all(), $rules, $message); if ($validator->fails()) { return Redirect::to('/')->withErrors($validator)->withInput(Input::except('password')); } else { $data = array('username' => Input::get('username'), 'password' => Input::get('password')); if (Auth::attempt($data)) { $data = DB::table('user')->select('user_id', 'level_user', 'username')->where('username', '=', Input::get('username'))->first(); //print_r($data); //echo $data->id_users; Session::put('user_id', $data->user_id); Session::put('level', $data->level_user); Session::put('username', $data->username); //print_r(Session::all()); return Redirect::to("/admin/beranda"); } else { Session::flash('messages', ' <div class="alert alert-danger alert-dismissable" > <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> <strong>Peringatan...</strong><br> Username dan password belum terdaftar pada sistem ! </div> '); return Redirect::to('/')->withInput(Input::except('password')); } } }
/** * 动作:修改当前账号密码 * @return Response */ public function putChangePassword() { $response = array(); // 获取所有表单数据 $data = Input::all(); $admin = Session::get("admin"); // 验证旧密码 if (!Hash::check($data['password_old'], $admin->pwd)) { $response['success'] = false; $response['message'] = '原始密码错误'; return Response::json($response); } // 创建验证规则 $rules = array('password' => 'alpha_dash|between:6,16|confirmed'); // 自定义验证消息 $messages = array('password.alpha_dash' => '密码格式不正确。', 'password.between' => '密码长度请保持在:min到:max位之间。', 'password.confirmed' => '两次输入的密码不一致。'); // 开始验证 $validator = Validator::make($data, $rules, $messages); if ($validator->passes()) { // 验证成功 // 更新用户 $admin->pwd = Hash::make(Input::get('password')); if ($admin->save()) { $response['success'] = true; $response['message'] = '密码修改成功'; } else { $response['success'] = false; $response['message'] = '密码修改失败'; } } else { $response['success'] = false; $response['message'] = $validator->errors->first(); } return Response::json($response); }
public function faqSend() { $question = new Question(); $input = Input::all(); $captcha_string = Input::get('g-recaptcha-response'); $captcha_response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6LcCwgATAAAAAKaXhPJOGPTBwX-n2-PPLZ7iupKj&response=' . $captcha_string); $captcha_json = json_decode($captcha_response); if ($captcha_json->success) { $rules = ["sujetQuestion" => "required", "mail" => "required|email", "contenuQuestion" => "required"]; $messages = ["required" => ":attribute est requis pour l'envoi d'une question", "email" => "L'adresse email précisée n'est pas valide"]; $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { $messages = $validator->messages(); Session::flash('flash_msg', "Certains champs spécifiés sont incorrects."); Session::flash('flash_type', "fail"); return Redirect::to(URL::previous())->withErrors($validator); } else { $question->fill($input)->save(); Session::flash('flash_msg', "Votre question nous est bien parvenue. Nous vous répondrons sous peu."); Session::flash('flash_type', "success"); return Redirect::to(URL::previous()); } } else { Session::flash('flash_msg', "Champ de vérification incorrect ou non coché."); Session::flash('flash_type', "fail"); return Redirect::to(URL::previous()); } }
public function crearProyecto() { $data = Input::all(); $ciclo = $data['cicle']; $ciclo == 1 ? $ciclo = 'Agosto-Enero' : ($ciclo = 'Enero-Julio'); //Valida los datos ingresados. $notificaciones = ['year.required' => '¡Escriba un año!', 'year.numeric' => '¡El año debe ser numérico!']; $validation = Validator::make($data, ['year' => 'required|numeric'], $notificaciones); if ($validation->passes()) { //Se revisa si había registros antes $temp = Proyecto::select('ciclo', 'anio')->where('ciclo', $ciclo)->where('anio', $data['year'])->get(); //Si aún no había registros, se añaden las horas disponbiles por aula y día. if (sizeof($temp) < 1) { $idProyecto = Proyecto::insertGetId(['ciclo' => $ciclo, 'anio' => $data['year']]); $aulas = Aula::count(); $horas = Hora::select('*')->where('id', '>', '0')->get(); for ($i = 2; $i <= $aulas; $i++) { for ($k = 0; $k < 5; $k++) { foreach ($horas as $hora) { $temp = new Disponible(); $temp->id_aula = $i; $temp->hora = $hora['id']; $temp->dia = $k; $temp->id_proyecto = $idProyecto; $temp->save(); } } } } return Redirect::to('/proyectos/'); } else { Input::flash(); return Redirect::to('/proyectos/editar-proyecto')->withInput()->withErrors($validation); } }
/** * Upload the file and store * the file path in the DB. */ public function store() { // Rules $rules = array('name' => 'required', 'file' => 'required|max:20000'); $messages = array('max' => 'Please make sure the file size is not larger then 20MB'); // Create validation $validator = Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $directory = "uploads/files/"; // Before anything let's make sure a file was uploaded if (Input::hasFile('file') && Request::file('file')->isValid()) { $current_file = Input::file('file'); $filename = Auth::id() . '_' . $current_file->getClientOriginalName(); $current_file->move($directory, $filename); $file = new Upload(); $file->user_id = Auth::id(); $file->project_id = Input::get('project_id'); $file->name = Input::get('name'); $file->path = $directory . $filename; $file->save(); return Redirect::back(); } $upload = new Upload(); $upload->user_id = Auth::id(); $upload->project_id = Input::get('project_id'); $upload->name = Input::get('name'); $upload->path = $directory . $filename; $upload->save(); return Redirect::back(); }
public function save () { $param = Input::all(); $validator = Validator::make($param, [ 'site_title' => 'required', 'meta_description' => 'required', 'meta_keywords' => 'required', 'email_support' => 'required|email', 'count_pagination' => 'required' ]); if ( $validator->fails() ) { $output = ''; $errors = $validator->messages()->toArray(); foreach ($errors as $error) { $output .= $error[0] . '<br>'; } return View::make('admin.elements.error')->with('errors', $output); } AppSettings::set('site_title', $param['site_title']); AppSettings::set('meta_description', $param['meta_description']); AppSettings::set('meta_keywords', $param['meta_keywords']); AppSettings::set('email_support', $param['email_support']); AppSettings::set('count_pagination', $param['count_pagination']); return Redirect::to(URL::previous()); }
function store() { $rules = array('icao' => 'alpha_num|required', 'iata' => 'alpha_num', 'name' => 'required', 'city' => 'required', 'lat' => 'required|numeric', 'lon' => 'required|numeric', 'elevation' => 'required|numeric', 'country_id' => 'required|exists:countries,id', 'website' => 'url'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { Messages::error($validator->messages()->all()); return Redirect::back()->withInput(); } if (is_null($airport = Airport::whereIcao(Input::get('icao'))->whereNew(true)->first())) { $airport = new Airport(); $airport->icao = Input::get('icao'); $airport->name = Input::get('name'); $airport->new = true; $airport->save(); } Diff::compare($airport, Input::all(), function ($key, $value, $model) { $change = new AirportChange(); $change->airport_id = $model->id; $change->user_id = Auth::id(); $change->key = $key; $change->value = $value; $change->save(); }, ['name', 'iata', 'city', 'country_id', 'lat', 'lon', 'elevation', 'website']); Messages::success('Thank you for your submission. We will check whether all information is correct and soon this airport might be available.'); return Redirect::back(); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { if (Auth::check()) { // validate // read more on validation at http://laravel.com/docs/validation $rules = array('username' => 'required', 'email' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::to('users/' . $id . '/edit')->withErrors($validator)->withInput(Input::except('password')); } else { // store $user = User::find($id); $user->username = Input::get('username'); $user->email = Input::get('email'); $user->save(); // redirect Session::flash('message', 'Successfully updated user'); return Redirect::to('users'); } } else { // User is not logged in Session::flash('message', 'Please log in'); return Redirect::to('/'); } }
public function postSave($id = null) { $validator = Validator::make(Input::all(), Appointment::$rules); if ($validator->passes()) { $event = Appointment::find(Input::get('id')); if (!$event) { $event = new Appointment(); } $calendar = Calendar::find(explode('/', Input::get('date'))[0]); if ($calendar) { $day = explode('/', Input::get('date'))[1]; if ($day > 0 && $day <= $calendar->number_of_days) { $event->name = Input::get('name'); $event->date = explode('/', Input::get('date'))[1]; $event->start_time = Input::get('start_time'); $event->end_time = Input::get('end_time'); $event->notes = Input::get('notes'); $event->calendar_id = $calendar->id; $event->group_id = Input::get('group_id'); $event->user_id = Auth::user()->id; $event->save(); return Response::json(array('status' => 'success', $event)); } else { $validator->messages()->add('date', 'The day is invalid.'); } } else { $validator->messages()->add('date', 'The month is invalid.'); } } return Response::json(array('status' => 'error', 'errors' => $validator->messages())); }
/** * 头像上传 * * 这里不直接注入自定义的 Request 类, 因为直接注入的话如果上传的文件不符合规则, 直接被拦截了, 进不到这个方法, 实现不了 AJAX 提交 * 因此在这方法里面进行验证, 再把错误用 json 返回到页面上 * * @param Request $request * * @return \Illuminate\Http\JsonResponse */ public function avatarUpload(Request $request) { $file = $request->file('avatar'); $avatarRequest = new AvatarRequest(); $validator = \Validator::make($request->only('avatar'), $avatarRequest->rules()); if ($validator->fails()) { return \Response::json(['success' => false, 'errors' => $validator->messages()]); } $user = $this->authRepository->user(); $destination = 'avatar/' . $user->username . '/'; // 文件最终存放目录 file_exists($destination) ? '' : mkdir($destination, 0777); $clientName = $file->getClientOriginalName(); // 原文件名 $extension = $file->getClientOriginalExtension(); // 文件扩展名 $newName = md5(date('ymd') . $clientName) . '.' . $extension; $avatarPath = '/' . $destination . $newName; $oldAvatar = substr($user->avatar, 1); // 旧头像路径, 把路径最前面的 / 删掉 if ($file->move($destination, $newName)) { $this->authRepository->update(['avatar' => $avatarPath], $user->id); file_exists($oldAvatar) ? unlink($oldAvatar) : ''; return \Response::json(['success' => true, 'avatar' => $avatarPath]); } }
public function postUpdate($id) { $archivo = Input::file('archivo'); $imagen = Input::file('imagen'); $validator = Validator::make(array('archivo' => $archivo, 'imagen' => $imagen), array('archivo' => 'mimes:png,jpeg,gif,txt,ppt,pdf,doc,xls', 'imagen' => 'mimes:png,jpeg,gif'), array('mimes' => 'Tipo de archivo inválido, solo se admite los formatos PNG, JPEG, y GIF')); if ($validator->fails()) { return Redirect::to($this->route . '/create')->with('msg_err', Lang::get('messages.companies_create_img_err')); } else { $arquivo = SFArquivos::find($id); $arquivo->titulo_archivo = Input::get('titulo_archivo'); $arquivo->id_categoria = Input::get('id_categoria'); $arquivo->resumem = Input::get('resumem'); $arquivo->tipo_archivo = Input::get('tipo_archivo'); if ($archivo != "") { $url = $archivo->getRealPath(); $extension = $archivo->getClientOriginalExtension(); $name = str_replace(' ', '', strtolower(Input::get('titulo_archivo'))) . date('YmdHis') . rand(2, 500 * 287) . '.' . $extension; $size = $archivo->getSize(); $mime = $archivo->getMimeType(); $archivo->move(public_path('uploads/arquivos/'), $name); $arquivo->archivo = $name; } if ($imagen != "") { $imagen = $this->uploadHeader($imagen); $arquivo->imagen = $imagen; } $arquivo->save(); return Redirect::to($this->route)->with('msg_success', Lang::get('messages.companies_create', array('title' => $arquivo->title))); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $validasi = Validator::make(Input::all(), Berita::$rules, Berita::$pesan); if ($validasi->fails()) { return Redirect::back()->withInput()->withErrors($validasi); } else { $berita = Berita::find($id); $berita->judul = Input::get('judul'); $berita->isi = Input::get('isi'); $berita->id_kategori = Input::get('kategori'); if (Input::hasFile('gambar')) { $file = Input::file('gambar'); $filename = str_random(5) . '-' . $file->getClientOriginalName(); $destinationPath = 'uploads/berita/'; $file->move($destinationPath, $filename); if ($berita->gambar) { $fotolama = $berita->gambar; $filepath = public_path() . DIRECTORY_SEPARATOR . 'uploads/berita' . DIRECTORY_SEPARATOR . $berita->gambar; try { File::delete($filepath); } catch (FileNotFoundException $e) { } } $berita->gambar = $filename; } $berita->save(); Session::flash('pesan', "<div class='alert alert-info'>Berita Berhasil diupdate</div>"); return Redirect::to('admin/berita'); } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { //Validate $rules = array('name' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the validation if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(Input::except('password')); } else { // Update $commodity = Commodity::find($id); $commodity->name = Input::get('name'); $commodity->description = Input::get('description'); $commodity->metric_id = Input::get('unit_of_issue'); $commodity->unit_price = Input::get('unit_price'); $commodity->item_code = Input::get('item_code'); $commodity->storage_req = Input::get('storage_req'); $commodity->min_level = Input::get('min_level'); $commodity->max_level = Input::get('max_level'); try { $commodity->save(); return Redirect::route('commodity.index')->with('message', trans('messages.success-updating-commodity'))->with('activecommodity', $commodity->id); } catch (QueryException $e) { Log::error($e); } } }
public function create() { $message = null; if ($val = \Input::get('val')) { /** * @var $privacy */ extract($val); if ($privacy == 1) { $validator = \Validator::make($val, ['public_name' => 'required|predefined|validalpha|min:3', 'public_url' => 'required|predefined|validalpha|min:3|alpha_dash|slug|unique:communities,slug']); } else { $validator = \Validator::make($val, ['private_name' => 'required|predefined|validalpha|min:3', 'private_url' => 'required|predefined|validalpha|min:3|alpha_dash|slug|unique:communities,slug']); } if (!$validator->fails()) { $community = $this->communityRepostory->create($val); if ($community) { //redirect to community page return \Redirect::to($community->present()->url()); } else { $message = trans('community.create-error'); } } else { $message = $validator->messages()->first(); } } return $this->preRender($this->theme->section('community.create', ['message' => $message]), $this->setTitle(trans('community.create'))); }
/** * Validate the Model * runs the validator and binds any errors to the model * * @param array $rules * @param array $messages * @return bool */ public function valid($rules = array(), $messages = array()) { // innocent until proven guilty $valid = true; if (!empty($rules) || !empty(static::$rules)) { // check for overrides $rules = empty($rules) ? static::$rules : $rules; $messages = empty($messages) ? static::$messages : $messages; // if the model exists, this is an update if ($this->exists) { // and only include dirty fields $data = $this->get_dirty(); // so just validate the fields that are being updated $rules = array_intersect_key($rules, $data); } else { // otherwise validate everything! $data = $this->attributes; } // construct the validator $validator = Validator::make($data, $rules, $messages); $valid = $validator->valid(); // if the model is valid, unset old errors if ($valid) { $this->errors->messages = array(); } else { $this->errors = $validator->errors; } } return $valid; }
public function postEdit($user) { $all_input = \Request::all(); $edit_rules = array('first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email'); $validator = \Validator::make($all_input, $edit_rules); if ($validator->passes()) { // save old password $old_password = $user->password; // update with all input $user->update($all_input); //restore old pw $user->password = $old_password; // set name alias $user->name = $all_input['first_name'] . ' ' . $all_input['last_name']; // set password only if posted if (isset($all_input['password']) && !empty($all_input['password'])) { $user->password = \Hash::make($all_input['password']); } // reset confirmation if (isset($all_input['confirmed'])) { $user->confirmed = 1; $user->confirmation_code = ""; } else { $user->confirmed = 0; } $user->update(); error_log("U " . json_encode($user)); error_log("I " . json_encode($all_input)); return redirect("/admin/users/{$user->id}/update"); } else { return redirect("/admin/users/{$user->id}/update")->withErrors($validator); } }
public function test_validacion_exitosa_con_clave_foranea_lugar() { $padre = Factory::create('App\\Lugar'); $lugar = Factory::attributesFor('App\\Lugar', ['lug_abreviatura' => 'asd', 'lug_nombre' => 'asd', 'lug_tipo' => 'pais', 'parent_lug_id' => $padre->lug_id]); $validator = Validator::make($lugar, $this->rules, $this->messages); $this->assertTrue($validator->passes(), 'Se esperaba que falle la validadicon.'); }
/** * Show the form for creating a new resource. * * @return Response */ public function save() { $rules = ['firstname' => 'required', 'lastname' => 'required', 'login' => 'required', 'address' => 'required', 'cpassword' => 'required', 'npassword' => 'required', 'cnpassword' => 'required']; $validator = \Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('/settings')->withinput(Input::all())->withErrors($validator); } else { if (Input::get('npassword') == Input::get('cnpassword')) { // $u = User::select('*')->where('password',Hash::make(Input::get('cpassword')))->first(); //return Hash::make(Input::get('cpassword')); //if(count($u)>0) { $user = User::find(Input::get('id')); $user->firstname = Input::get('firstname'); $user->lastname = Input::get('lastname'); // $user->login = Input::get('login'); $user->address = Input::get('address'); // $user->email = Input::get('email'); $user->password = Hash::make(Input::get('npassword')); $user->save(); return Redirect::to('/settings')->with('success', 'Settings is changed please relogin the site.'); /*} else { $errorMessages = new Illuminate\Support\MessageBag; $errorMessages->add('notmatch', 'Current Password did not match!'); return Redirect::to('/settings')->withErrors($errorMessages); }*/ } else { $errorMessages = new Illuminate\Support\MessageBag(); $errorMessages->add('notmatch', 'New Password and confirm password did not match!'); return Redirect::to('/settings')->withErrors($errorMessages); } } }
public static function updateCivil($input, $id) { $answer = []; $rules = ['number_civil' => 'required', 'date' => 'required', 'demandant' => 'required', 'defendant' => 'required', 'matery' => 'required', 'secretary' => 'required', 'file' => 'required']; $validation = Validator::make($input, $rules); if ($validation->fails()) { $answer['message'] = $validation; $answer['error'] = true; } else { $civil = self::find($id); $civil->number_civil = $input['number_civil']; $civil->date = $input['date']; $civil->demandant = $input['demandant']; $civil->defendant = $input['defendant']; $civil->matery = $input['matery']; $civil->secretary = $input['secretary']; $civil->file = $input['file']; $civil->references = $input['references']; $civil->description = $input['description']; if ($civil->save()) { $answer['message'] = 'Editado con exito!'; $answer['error'] = false; } else { $answer['message'] = 'CIVIL UPDATE error, team noob!'; $answer['error'] = false; } } return $answer; }
public function add() { if (!\Config::get('game-create-allowed')) { return \Redirect::to(\URL::previous()); } $message = null; if ($val = \Input::get('val')) { $validator = \Validator::make($val, ['title' => 'required|predefined|validalpha|min:3']); if (!$validator->fails()) { $game = $this->gameRepository->add($val); if ($game) { //send to game list if (\Config::get('game-create-allowed') and !\Auth::user()->isAdmin()) { $message = "<strong>Thanks for adding game:</strong> One of our administrator will now inspect your game and confirm very soon"; } else { return \Redirect::to($game->present()->url()); } } else { $message = trans('game.error'); } } else { $message = $validator->messages()->first(); } } return $this->preRender($this->theme->section('game.add', ['message' => $message, 'categories' => $this->categoryRepository->listAll()]), $this->setTitle(trans('game.add-games'))); }
public function doLogin() { // validate the info, create rules for the inputs $rules = array('email' => 'required|email', 'password' => 'required|alphaNum|min:3'); // run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules); // if the validator fails, redirect back to the form if ($validator->fails()) { return Redirect::to('login')->withErrors($validator)->withInput(Input::except('password')); // send back the input (not the password) so that we can repopulate the form } else { // create our user data for the authentication $userdata = array('email' => Input::get('email'), 'password' => Input::get('password')); // attempt to do the login if (Auth::attempt($userdata)) { // validation successful! // redirect them to the secure section or whatever // return Redirect::to('secure'); // for now we'll just echo success (even though echoing in a controller is bad) echo 'SUCCESS!'; } else { // validation not successful, send back to form return Redirect::to('login'); } } }
/** * * Process the add/edit project form. * @return type */ public function post_manage() { $input = Input::all(); if (!$input['id']) { $input['id'] = null; } $rules = array('name' => array('required', 'match:/[a-z0-9\\-]+/', "unique:gc_projects,name,{$input['id']}"), 'repo' => array('required', 'min:2', 'match:/[a-z0-9\\-]+/', "unique:gc_projects,repo,{$input['id']}"), 'path' => 'required'); $m = new Messages(); $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::to(handles('orchestra::resources/githubdeploys/manage/' . $input['id']))->with_input()->with_errors($v); } $project = Projects::find($input['id']); if (!$project) { $project = new Projects(); $project->user_id = Auth::user()->id; if (!is_dir($input['path'])) { if (mkdir($input['path'], 0777, true)) { $m->add('success', "Created project root dir!"); } } } foreach ($input as $property => $value) { $project->{$property} = $value; } $project->save(); $m->add('success', "Project modified!"); return Redirect::to(handles('orchestra::resources/githubdeploys'))->with('message', $m->serialize()); }
public function postUpload() { $agente = Agente::find(1); if (Input::hasFile('file')) { $file = Input::file('file'); $name = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $size = File::size($file); //dd($extension); $data = array('nombre' => $name, 'extension' => $extension, 'size' => $size); $rules = array('extension' => 'required|mimes:jpeg'); $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'unique' => 'La factura ingresada ya está agregada en la base de datos.', 'confirmed' => 'Los passwords no coinciden.', 'mimes' => 'El campo :attribute debe ser un archivo de tipo :values.'); $validation = Validator::make($rules, $messages); if ($validation->fails()) { return Redirect::route('logo-post')->withInput()->withErrors($validation); } else { if ($extension != 'jpg') { return Redirect::route('logo-post')->with('global', 'Es necesario que la imagen sea de extension .jpg.'); } else { $path = public_path() . '/assets/img/'; $newName = 'logo'; $subir = $file->move($path, $newName . '.' . $extension); return Redirect::route('agente.index')->with('create', 'El logo ha sido actualizado correctamente!'); } } } else { return Redirect::route('logo-post')->with('global', 'Es necesario que selecciones una imagen.'); } }
/** * Saves user submissions for Independent Sponsor requests. */ public function putRequest() { //Validate input $rules = array('address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'phone' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { return Response::json($this->growlMessage($validation->messages()->all(), 'error'), 400); } //Add new user information to their record $user = Auth::user(); $user->address1 = Input::get('address1'); $user->address2 = Input::get('address2'); $user->city = Input::get('city'); $user->state = Input::get('state'); $user->postal_code = Input::get('postal_code'); $user->phone = Input::get('phone'); $user->save(); if (!$user->getSponsorStatus()) { //Add UserMeta request $request = new UserMeta(); $request->meta_key = UserMeta::TYPE_INDEPENDENT_SPONSOR; $request->meta_value = 0; $request->user_id = $user->id; $request->save(); } return Response::json(); }
/** * Define my relationship to media */ public static function validateMedia($file) { if ($file->isValid()) { $validator = Validator::make(array('file' => $file), array('file' => 'mimes:png,gif,jpeg|max:50000')); return $validator; } }
public static function updateNotary($input, $id) { $answer = []; $rules = ['name' => 'required']; $validation = Validator::make($input, $rules); if ($validation->fails()) { $answer['message'] = $validation; $answer['error'] = true; } else { $notary = Notary::find($id); $notary->name = $input['name']; if (Input::has('status')) { $notary->status = $input['status']; } else { $notary->status = 0; } if ($notary->save()) { $answer['message'] = 'Editado con exito!'; $answer['error'] = false; } else { $answer['message'] = 'NOTARY UPDATE error, team noob!'; $answer['error'] = false; } } return $answer; }
public function short() { $request = \Request::all(); $target = ['url' => $request['url']]; $rules = ['url' => 'required|url']; $message = ['url' => '请输入合法的链接地址', 'required' => '链接地址不能为空']; $validation = \Validator::make($target, $rules, $message); if ($validation->fails()) { $errmes = $validation->errors()->toArray(); //组装json $info = json_encode(['code' => 0, 'message' => $errmes['url'][0]]); return $info; } else { //进一步处理 //判断当前url在数据库中是否存在 $record = Urls::where('url', $request['url'])->first(); if (!empty($record)) { //组装json $shorturl = $record->short; $info = json_encode(['code' => '1', 'message' => 'http://www.url.dev/' . $shorturl]); return $info; } else { //生成短链并插入数据库 $short = Urls::get_unique_short_url(); $insert = Urls::insert(['url' => $request['url'], 'short' => $short]); if ($insert) { $info = json_encode(['code' => 1, 'message' => 'http://www.url.dev/' . $short]); return $info; } else { $info = json_encode(['code' => 0, 'message' => '生成失败,请重试']); return $info; } } } }
/** * Saves user submissions for Independent Sponsor requests. */ public function postRequest() { //Grab input $address1 = Input::get('address1'); $address2 = Input::get('address2'); $city = Input::get('city'); $state = Input::get('state'); $postal = Input::get('postal'); $phone = Input::get('phone'); $all_input = Input::all(); //Validate input $rules = array('address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal' => 'required', 'phone' => 'required'); $validation = Validator::make($all_input, $rules); if ($validation->fails()) { return Redirect::to('/documents/sponsor/request')->withInput()->withErrors($validation); } //Add new user information to their record $user = Auth::user(); $user->address1 = $address1; $user->address2 = $address2; $user->city = $city; $user->state = $state; $user->postal_code = $postal; $user->phone = $phone; $user->save(); //Add UserMeta request $request = new UserMeta(); $request->meta_key = UserMeta::TYPE_INDEPENDENT_SPONSOR; $request->meta_value = 0; $request->user_id = $user->id; $request->save(); return Redirect::to('/user/edit/' . $user->id)->with('message', 'Your request has been received.'); }
/** * Show the form for creating a new resource. * GET /tasks/create * * @return Response */ public function create() { // Rules $rules = array('weight' => 'integer|between:1,5', 'name' => 'required'); // Custom messages $messages = array('between' => 'The :attribute must be between :min - :max.', 'integer' => ':attribute must be a number'); // Create validation $validator = Validator::make(Input::all(), $rules, $messages); // Check validation if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } // Insert the task to database $task = new Task(); $task->project_id = Input::get('projectId'); $task->user_id = Auth::id(); $task->name = Input::get('name'); $task->weight = Input::get('weight'); if (!Input::get('weight')) { $task->weight = 1; } $task->state = "incomplete"; $task->save(); // Increase the users overall task count $user = User::find(Auth::id()); $user->tasks_created = $user->tasks_created + 1; $user->save(); return Redirect::back()->with('success', Input::get('name') . " has been created."); }
/** * Reset the given user's password. * * @param Request $request * @return Response */ public function postReset(Request $request) { // $this->validate($request, [ // 'token' => 'required', // 'email' => 'required|email|min:6|max:255', // 'password' => 'required|confirmed', // ]); $validator = \Validator::make($request->all(), ['token' => 'required', 'email' => 'required|email|min:6|max:255', 'password' => 'required|confirmed']); if ($validator->fails()) { return \Response::json(['error' => ['messages' => $validator->getMessageBag(), 'rules' => $validator->getRules()]]); } $credentials = $request->only('email', 'password', 'password_confirmation', 'token'); $response = $this->passwords->reset($credentials, function ($user, $password) { if ($user->activated == 0) { return "pasword.user_not_active"; } $user->password = bcrypt($password); $user->save(); $this->auth->login($user); }); switch ($response) { case PasswordBroker::PASSWORD_RESET: return \Response::json(['success' => 'true']); //return redirect($this->redirectPath()); //return redirect($this->redirectPath()); default: return \Response::json(['success' => 'false', 'status' => trans($response)]); /*return redirect()->back() ->withInput($request->only('email')) ->withErrors(['email' => trans($response)]);*/ } }