Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. Route::group(array('prefix' => 'account'), function(){
  2. Route::get('register', array(
  3. 'before' => 'guest',
  4. 'as' => 'account-create',
  5. 'uses' => 'AccountController@getCreate'
  6. ));
  7.  
  8. Route::post('register', array(
  9. 'before' => 'guest|csrf',
  10. 'as' => 'account-create-post',
  11. 'uses' => 'AccountController@postCreate'
  12. ));
  13.  
  14. Route::get('register/confirm', array(
  15. 'before' => 'guest',
  16. 'as' => 'account-create-confirm',
  17. 'uses' => 'AccountController@getCreateConfirm'
  18. ));
  19.  
  20. Route::post('register/confirm', array(
  21. 'before' => 'guest|csrf',
  22. 'as' => 'account-create-confirm-post',
  23. 'uses' => 'AccountController@postCreateConfirm'
  24. ));
  25.  
  26. Route::get('register/complete', array(
  27. 'before' => 'guest',
  28. 'as' => 'account-create-complete',
  29. 'uses' => 'AccountController@getCreateComplete'
  30. ));
  31. });
  32.  
  33. <?php
  34. class AccountController extends BaseController {
  35.  
  36. private $form_session = 'register_form';
  37.  
  38. public function getCreate()
  39. {
  40. if(Session::has($this->form_session))
  41. {
  42. // get forms session data
  43. $data = Session::get($this->form_session);
  44.  
  45. // clear forms session data
  46. Session::forget($this->form_session);
  47.  
  48. // load the form view /w the session data as input
  49. return View::make('account.create')->with('input',$data);
  50. }
  51.  
  52. return View::make('account.create');
  53. }
  54.  
  55. public function postCreate()
  56. {
  57. // set the form input to the session
  58. Session::set($this->form_session, Input::all());
  59.  
  60. $validation_rules = array(
  61. 'email' => 'required|max:50|email|unique:users',
  62. 'password' => 'required|max:60|min:6',
  63. 'password_conf' => 'required|max:60|same:password'
  64. );
  65.  
  66. $validator = Validator::make(Input::all(), $validation_rules);
  67.  
  68. // get forms session data
  69. $data = Session::get($this->form_session);
  70.  
  71. // Return back to form w/ validation errors & session data as input
  72. if($validator->fails()) {
  73. return Redirect::back()->withErrors($validator);
  74. }
  75.  
  76. // redirect to the confirm step
  77. return Redirect::route('account-create-confirm');
  78. }
  79.  
  80. public function getCreateConfirm()
  81. {
  82. // prevent access without filling out step1
  83. if(!Session::has($this->form_session)) {
  84. return Redirect::route('account-create');
  85. }
  86.  
  87. // get forms session data
  88. $data = Session::get($this->form_session);
  89.  
  90. // retun the confirm view w/ session data as input
  91. return View::make('account.create-confirm')->with('input', $data);
  92. }
  93.  
  94. public function postCreateConfirm()
  95. {
  96. $data = Session::get($this->form_session);
  97.  
  98. // insert into DB
  99. // send emails
  100. // etc.
  101.  
  102. // clear forms session data
  103. Session::forget($this->form_session);
  104.  
  105. // redirect to the complete/success step
  106. return Redirect::route('account-create-complete');
  107. }
  108.  
  109. public function getCreateComplete() {
  110. return View::make('account.create-complete');
  111. }
  112. }
  113.  
  114. <form action="{{ URL::route('account-create-post') }}" method="post">
  115.  
  116. Email: <input type="text" name="email" value="{{ (isset($input['email'])) ? e($input['email']) : '' }}">
  117. @if($errors->has('email'))
  118. {{ $errors->first('email') }}
  119. @endif
  120. <br />
  121.  
  122. Password: <input type="text" name="password" value="">
  123. @if($errors->has('password'))
  124. {{ $errors->first('password') }}
  125. @endif
  126. <br />
  127.  
  128. Password Confirm: <input type="text" name="password_conf" value="">
  129. @if($errors->has('password_conf'))
  130. {{ $errors->first('password_conf') }}
  131. @endif
  132. <br />
  133.  
  134. {{ Form::token() }}
  135.  
  136. <input type="submit" value="Confirm">
  137.  
  138. </form>
  139.  
  140. Email: {{ $input['email']; }}
  141. Password: {{ $input['password']; }}
  142.  
  143. <form action="{{ URL::route('account-create-confirm-post') }}" method="post">
  144. {{ Form::token() }}
  145. <a href="{{ URL::previous() }}">return</a>
  146. <input type="submit" name="submit_forward" value="Submit">
  147. </form>
  148.  
  149. Email: {{ $input['email'] }}
  150. Password: {{ $input['password'] }}
  151.  
  152. <form action="{{ URL::route('account-create-confirm-post') }}" method="post">
  153. <input type="hidden" name="email" value="{{ $input['email'] }}">
  154. <input type="hidden" name="password" value="{{ $input['password'] }}">
  155. {{ Form::token() }}
  156. <a href="{{ URL::previous() }}">return</a>
  157. <input type="submit" name="submit_forward" value="Submit">
  158. </form>
  159.  
  160. Email: {{ $input['email'] }}
  161. Password: {{ $input['password'] }}
  162.  
  163. <form action="{{ URL::route('account-create-confirm-post') }}" method="post">
  164. <input type="hidden" name="id" value="{{ $user_id }}">
  165. {{ Form::token() }}
  166. <a href="{{ URL::previous() }}">return</a>
  167. <input type="submit" name="submit_forward" value="Submit">
  168. </form>
  169.  
  170. public function getCreate() {
  171. if ($this->formRememberService->hasData()) {
  172. return View::make('account.create')
  173. ->with('input', $this->formRememberService->getData());
  174. }
  175. return View::make('account.create');
  176. }
  177.  
  178. public function postCreate() {
  179. $this->formRememberService->saveData(Input::all());
  180. // ...
  181. }
  182.  
  183. public function postCreateConfirm() {
  184. // ...
  185. $this->formRememberService->clear();
  186. return Redirect::route('account-create-complete');
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement