Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- home:
- path: /
- controller: AppControllerHomeController::index
- methods: [GET]
- login:
- path: /login
- controller: AppControllerHomeController::login
- methods: [POST]
- register:
- path: /register
- controller: AppControllerHomeController::register
- methods: [POST]
- timeline:
- path: /timeline
- controller: AppControllerTimelineController::index
- methods: [GET]
- //
- <?php
- namespace AppEntity;
- use DoctrineORMMapping as ORM;
- /**
- * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
- * @ORMTable(name="users")
- */
- class User
- {
- /**
- * @ORMId
- * @ORMGeneratedValue
- * @ORMColumn(type="integer")
- */
- private $id;
- /**
- * @ORMColumn(type="string", length=50)
- */
- private $username;
- /**
- * @ORMColumn(type="string", length=100)
- */
- private $email;
- /**
- * @ORMColumn(type="string", length=100)
- */
- private $password;
- /**
- * @ORMColumn(type="string", length=50)
- */
- private $firstName;
- /**
- * @ORMColumn(type="string", length=50)
- */
- private $lastName;
- /**
- * @ORMColumn(type="datetime")
- */
- private $createdAt;
- public function getId()
- {
- return $this->id;
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function getEmail()
- {
- return $this->email;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function getFirstName()
- {
- return $this->firstName;
- }
- public function getLastName()
- {
- return $this->lastName;
- }
- public function getCreatedAt()
- {
- return $this->createdAt;
- }
- public function setUsername($username)
- {
- $this->username = $username;
- }
- public function setEmail($email)
- {
- $this->email = $email;
- }
- public function setPassword($password)
- {
- $this->password = $password;
- }
- public function setFirstName($firstName)
- {
- $this->firstName = $firstName;
- }
- public function setLastName($lastName)
- {
- $this->lastName = $lastName;
- }
- public function setCreatedAt($createdAt)
- {
- $this->createdAt = $createdAt;
- }
- }
- <?php
- namespace AppController;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentHttpFoundationResponse;
- use AppEntityUser;
- class HomeController extends Controller
- {
- public function index() {
- return $this->render('home/index.html.twig');
- }
- public function login(Request $request) {
- // ?????
- }
- public function register(Request $request) {
- $user = new User();
- // ?????
- }
- }
- ...
- <form action="{{ path('login') }}" id="signInForm" role="form"
- method="POST" class="visible">
- <h2>Sign In</h2>
- <hr class="colorgraph">
- <div class="form-group">
- <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address">
- </div>
- <div class="form-group">
- <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password">
- </div>
- <span class="button-checkbox">
- <button type="button" class="btn btn-info active" data-color="info">
- <i class="state-icon glyphicon glyphicon-check"></i> Remember Me</button>
- <input type="checkbox" name="remember_me" id="remember_me" class="hidden">
- <a href="" class="btn btn-link pull-right">Forgot Password?</a>
- </span>
- <hr class="colorgraph">
- <div class="row">
- <div class="col-xs-6 col-sm-6 col-md-6">
- <input type="submit" class="btn btn-lg btn-success btn-block" value="Sign In">
- </div>
- <div class="col-xs-6 col-sm-6 col-md-6">
- <a id="registerBtn" href="#" class="btn btn-lg btn-block btn-toggle">To Register</a>
- </div>
- </div>
- </form>
- <form action="{{ path('register') }}" id="registerForm" role="form" method="POST">
- <h2>
- Please Sign Up
- <small>It's free and always will be.</small>
- </h2>
- <hr class="colorgraph">
- <div class="row">
- <div class="col-xs-12 col-sm-6 col-md-6">
- <div class="form-group">
- <input type="text" name="first_name" id="first_name" class="form-control input-lg" placeholder="First Name" tabindex="1">
- </div>
- </div>
- <div class="col-xs-12 col-sm-6 col-md-6">
- <div class="form-group">
- <input type="text" name="last_name" id="last_name" class="form-control input-lg" placeholder="Last Name" tabindex="2">
- </div>
- </div>
- </div>
- <div class="form-group">
- <input type="text" name="display_name" id="display_name" class="form-control input-lg" placeholder="Display Name" tabindex="3">
- </div>
- <div class="form-group">
- <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address" tabindex="4">
- </div>
- <div class="row">
- <div class="col-xs-12 col-sm-6 col-md-6">
- <div class="form-group">
- <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="5">
- </div>
- </div>
- <div class="col-xs-12 col-sm-6 col-md-6">
- <div class="form-group">
- <input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-lg" placeholder="Confirm Password"
- tabindex="6">
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-xs-4 col-sm-3 col-md-3">
- <span class="button-checkbox">
- <button type="button" class="btn" data-color="info" tabindex="7">I Agree</button>
- <input type="checkbox" name="t_and_c" id="t_and_c" class="hidden" value="1">
- </span>
- </div>
- <div class="col-xs-8 col-sm-9 col-md-9">
- By clicking
- <strong class="label label-primary">Register</strong>, you agree to the
- <a href="#" data-toggle="modal" data-target="#t_and_c_m">Terms and Conditions</a> set out by this site, including our Cookie Use.
- </div>
- </div>
- <hr class="colorgraph">
- <div class="row">
- <div class="col-xs-6 col-sm-6 col-md-6">
- <input type="submit" value="Register" class="btn btn-primary btn-block btn-lg" tabindex="7">
- </div>
- <div class="col-xs-6 col-sm-6 col-md-6">
- <a id="signInBtn" href="#" class="btn btn-block btn-lg btn-toggle">To Sign In</a>
- </div>
- </div>
- </form>
- ...
- public function login(Request $request) {
- $email = $request->get('email');
- $password = $request->get('password');
- $repository = $this->getDoctrine()->getRepository(User::class);
- $user = $repository->findOneBy([
- 'email' => $email,
- 'password' => $password
- ]);
- if($user) {
- // TODO: Set session
- return $this->redirectToRoute('timeline');
- }
- return $this->redirectToRoute('home');
- }
- public function register(Request $request) {
- $user = new User();
- $firstName = $request->get('first_name');
- $lastName = $request->get('last_name');
- $nickname = $request->get('display_name');
- $email = $request->get('email');
- $password = $request->get('password');
- $password2 = $request->get('password_confirmation');
- // VALIDATION
- return $this->render('message.html.twig', [
- 'header' => 'Congratulations',
- 'title' => 'Welcome <b>'. ucfirst($firstName) .' '. ucfirst($lastName) .'</b>!',
- 'message' => 'The registration process completed correctly!
- An activation link has been sent to your e-mail address.',
- 'button' => [
- 'href' => $this->generateUrl('home'),
- 'text' => 'To Sign In'
- ]
- ]);
- }
Add Comment
Please, Sign In to add comment