Guest User

Untitled

a guest
Dec 7th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.59 KB | None | 0 0
  1. home:
  2. path: /
  3. controller: AppControllerHomeController::index
  4. methods: [GET]
  5.  
  6. login:
  7. path: /login
  8. controller: AppControllerHomeController::login
  9. methods: [POST]
  10.  
  11. register:
  12. path: /register
  13. controller: AppControllerHomeController::register
  14. methods: [POST]
  15.  
  16. timeline:
  17. path: /timeline
  18. controller: AppControllerTimelineController::index
  19. methods: [GET]
  20.  
  21. //
  22.  
  23. <?php
  24.  
  25. namespace AppEntity;
  26.  
  27. use DoctrineORMMapping as ORM;
  28.  
  29. /**
  30. * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
  31. * @ORMTable(name="users")
  32. */
  33. class User
  34. {
  35. /**
  36. * @ORMId
  37. * @ORMGeneratedValue
  38. * @ORMColumn(type="integer")
  39. */
  40. private $id;
  41.  
  42. /**
  43. * @ORMColumn(type="string", length=50)
  44. */
  45. private $username;
  46.  
  47. /**
  48. * @ORMColumn(type="string", length=100)
  49. */
  50. private $email;
  51.  
  52. /**
  53. * @ORMColumn(type="string", length=100)
  54. */
  55. private $password;
  56.  
  57. /**
  58. * @ORMColumn(type="string", length=50)
  59. */
  60. private $firstName;
  61.  
  62. /**
  63. * @ORMColumn(type="string", length=50)
  64. */
  65. private $lastName;
  66.  
  67. /**
  68. * @ORMColumn(type="datetime")
  69. */
  70. private $createdAt;
  71.  
  72. public function getId()
  73. {
  74. return $this->id;
  75. }
  76.  
  77. public function getUsername()
  78. {
  79. return $this->username;
  80. }
  81.  
  82. public function getEmail()
  83. {
  84. return $this->email;
  85. }
  86.  
  87. public function getPassword()
  88. {
  89. return $this->password;
  90. }
  91.  
  92. public function getFirstName()
  93. {
  94. return $this->firstName;
  95. }
  96.  
  97. public function getLastName()
  98. {
  99. return $this->lastName;
  100. }
  101.  
  102. public function getCreatedAt()
  103. {
  104. return $this->createdAt;
  105. }
  106.  
  107. public function setUsername($username)
  108. {
  109. $this->username = $username;
  110. }
  111.  
  112. public function setEmail($email)
  113. {
  114. $this->email = $email;
  115. }
  116.  
  117. public function setPassword($password)
  118. {
  119. $this->password = $password;
  120. }
  121.  
  122. public function setFirstName($firstName)
  123. {
  124. $this->firstName = $firstName;
  125. }
  126.  
  127. public function setLastName($lastName)
  128. {
  129. $this->lastName = $lastName;
  130. }
  131.  
  132. public function setCreatedAt($createdAt)
  133. {
  134. $this->createdAt = $createdAt;
  135. }
  136. }
  137.  
  138. <?php
  139.  
  140. namespace AppController;
  141.  
  142. use SymfonyBundleFrameworkBundleControllerController;
  143. use SymfonyComponentHttpFoundationRequest;
  144. use SymfonyComponentHttpFoundationResponse;
  145. use AppEntityUser;
  146.  
  147. class HomeController extends Controller
  148. {
  149. public function index() {
  150. return $this->render('home/index.html.twig');
  151. }
  152.  
  153. public function login(Request $request) {
  154. // ?????
  155. }
  156.  
  157. public function register(Request $request) {
  158. $user = new User();
  159. // ?????
  160. }
  161. }
  162.  
  163. ...
  164.  
  165. <form action="{{ path('login') }}" id="signInForm" role="form"
  166. method="POST" class="visible">
  167. <h2>Sign In</h2>
  168. <hr class="colorgraph">
  169. <div class="form-group">
  170. <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address">
  171. </div>
  172. <div class="form-group">
  173. <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password">
  174. </div>
  175. <span class="button-checkbox">
  176. <button type="button" class="btn btn-info active" data-color="info">
  177. <i class="state-icon glyphicon glyphicon-check"></i>&nbsp;Remember Me</button>
  178. <input type="checkbox" name="remember_me" id="remember_me" class="hidden">
  179. <a href="" class="btn btn-link pull-right">Forgot Password?</a>
  180. </span>
  181. <hr class="colorgraph">
  182. <div class="row">
  183. <div class="col-xs-6 col-sm-6 col-md-6">
  184. <input type="submit" class="btn btn-lg btn-success btn-block" value="Sign In">
  185. </div>
  186. <div class="col-xs-6 col-sm-6 col-md-6">
  187. <a id="registerBtn" href="#" class="btn btn-lg btn-block btn-toggle">To Register</a>
  188. </div>
  189. </div>
  190. </form>
  191. <form action="{{ path('register') }}" id="registerForm" role="form" method="POST">
  192. <h2>
  193. Please Sign Up
  194. <small>It's free and always will be.</small>
  195. </h2>
  196. <hr class="colorgraph">
  197. <div class="row">
  198. <div class="col-xs-12 col-sm-6 col-md-6">
  199. <div class="form-group">
  200. <input type="text" name="first_name" id="first_name" class="form-control input-lg" placeholder="First Name" tabindex="1">
  201. </div>
  202. </div>
  203. <div class="col-xs-12 col-sm-6 col-md-6">
  204. <div class="form-group">
  205. <input type="text" name="last_name" id="last_name" class="form-control input-lg" placeholder="Last Name" tabindex="2">
  206. </div>
  207. </div>
  208. </div>
  209. <div class="form-group">
  210. <input type="text" name="display_name" id="display_name" class="form-control input-lg" placeholder="Display Name" tabindex="3">
  211. </div>
  212. <div class="form-group">
  213. <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address" tabindex="4">
  214. </div>
  215. <div class="row">
  216. <div class="col-xs-12 col-sm-6 col-md-6">
  217. <div class="form-group">
  218. <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="5">
  219. </div>
  220. </div>
  221. <div class="col-xs-12 col-sm-6 col-md-6">
  222. <div class="form-group">
  223. <input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-lg" placeholder="Confirm Password"
  224. tabindex="6">
  225. </div>
  226. </div>
  227. </div>
  228. <div class="row">
  229. <div class="col-xs-4 col-sm-3 col-md-3">
  230. <span class="button-checkbox">
  231. <button type="button" class="btn" data-color="info" tabindex="7">I Agree</button>
  232. <input type="checkbox" name="t_and_c" id="t_and_c" class="hidden" value="1">
  233. </span>
  234. </div>
  235. <div class="col-xs-8 col-sm-9 col-md-9">
  236. By clicking
  237. <strong class="label label-primary">Register</strong>, you agree to the
  238. <a href="#" data-toggle="modal" data-target="#t_and_c_m">Terms and Conditions</a> set out by this site, including our Cookie Use.
  239. </div>
  240. </div>
  241.  
  242. <hr class="colorgraph">
  243. <div class="row">
  244. <div class="col-xs-6 col-sm-6 col-md-6">
  245. <input type="submit" value="Register" class="btn btn-primary btn-block btn-lg" tabindex="7">
  246. </div>
  247. <div class="col-xs-6 col-sm-6 col-md-6">
  248. <a id="signInBtn" href="#" class="btn btn-block btn-lg btn-toggle">To Sign In</a>
  249. </div>
  250. </div>
  251. </form>
  252. ...
  253.  
  254. public function login(Request $request) {
  255. $email = $request->get('email');
  256. $password = $request->get('password');
  257.  
  258. $repository = $this->getDoctrine()->getRepository(User::class);
  259. $user = $repository->findOneBy([
  260. 'email' => $email,
  261. 'password' => $password
  262. ]);
  263.  
  264. if($user) {
  265. // TODO: Set session
  266. return $this->redirectToRoute('timeline');
  267. }
  268.  
  269. return $this->redirectToRoute('home');
  270. }
  271.  
  272. public function register(Request $request) {
  273. $user = new User();
  274.  
  275. $firstName = $request->get('first_name');
  276. $lastName = $request->get('last_name');
  277. $nickname = $request->get('display_name');
  278. $email = $request->get('email');
  279. $password = $request->get('password');
  280. $password2 = $request->get('password_confirmation');
  281.  
  282. // VALIDATION
  283.  
  284. return $this->render('message.html.twig', [
  285. 'header' => 'Congratulations',
  286. 'title' => 'Welcome <b>'. ucfirst($firstName) .' '. ucfirst($lastName) .'</b>!',
  287. 'message' => 'The registration process completed correctly!
  288. An activation link has been sent to your e-mail address.',
  289. 'button' => [
  290. 'href' => $this->generateUrl('home'),
  291. 'text' => 'To Sign In'
  292. ]
  293. ]);
  294. }
Add Comment
Please, Sign In to add comment