Created
April 7, 2013 19:22
-
-
Save dcrystalj/5332069 to your computer and use it in GitHub Desktop.
Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Provider extends BaseController { | |
//rules for registering | |
public $rules = array( | |
'sname' => 'required|max:20|alpha', | |
'email' => 'required|email|unique:users', | |
); | |
public $rules1 = array( | |
'password' => 'same:password_confirmation|between:4,20|confirmed', | |
'password_confirmation' => 'required', | |
); | |
public function index() | |
{ | |
return Redirect::to('/'); | |
} | |
public function create() | |
{ | |
return View::make('Provider.registerP')->with('rules', $this->rules); | |
} | |
public function store() | |
{ | |
$validation = Validator::make(Input::all(),$this->rules); | |
if($validation->fails()) | |
{ | |
Input::flash(); //input data remains in form | |
return Redirect::to('provider/create')->withErrors($validation); | |
} | |
else | |
{ | |
//save user and send mail with confirmation link | |
$user = new User; | |
$user->name = Input::get( 'sname' ); | |
$user->email = Input::get( 'email' ); | |
$user->save(); | |
Config::set('auth.reminder.email', 'emails.auth.welcome'); | |
return Password::remind(['email' => $user->email ], function($m) | |
{ | |
$m->setCharset('UTF-8'); | |
}) ; | |
} | |
} | |
/** | |
* Display the specified resource. | |
* | |
* @param int $id | |
* @return Response | |
*/ | |
public function show($id) | |
{ | |
// | |
} | |
public function edit($id) | |
{ | |
return View::make('Provider.ProviderServiceSettings'); | |
} | |
public function update($id) | |
{ | |
$rules = array('Service Name:' => 'required|max:20|alpha', | |
'E-mail:' => 'email', | |
'Change password:' => 'confirmed'); | |
$validation = Validator::make(Input::all(),$rules); | |
if($validation->fails()) | |
{ | |
return Redirect::to('provider/edit')->withErrors($validation); | |
} | |
else | |
{ | |
return View::make('find'); | |
} | |
} | |
public function destroy($id) | |
{ | |
// | |
} | |
public function getConfirm($token) | |
{ | |
return View::make('Provider.confirmation') | |
->with('rules',$this->rules1) | |
->with('token',$token); | |
} | |
public function postConfirm($token) | |
{ | |
//validation | |
$validation = Validator::make(Input::all(),$this->rules1); | |
if($validation->fails()) | |
{ | |
return Redirect::to('provider/confirm/' . $token)->withErrors($validation)->with('rules',$this->rules1); | |
} | |
//save | |
$remind = DB::table('password_reminders')->where('token', Input::get('token'))->first(); | |
if($remind) $user = User::where('email',$remind->email)->first(); | |
if(isset($user) ){ | |
$user->password = Hash::make(Input::get('password')); | |
$user->confirmed = 1; | |
$user->save(); | |
return View::make('home')->with('message','Success'); | |
} | |
return Redirect::to('provider/confirm/' . $token) | |
->with('status','Wrong token') | |
->with('rules',$this->rules1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment