コード例 #1
0
 public function addUserAction(Request $request)
 {
     $user = new AddUser();
     $form = $this->createForm(UserType::class, $user);
     // 2) handle the submit (will only happen on POST)
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $login = new Login();
         $password = $this->get('security.password_encoder')->encodePassword($login, $user->getPassword());
         $user->setPassword($password);
         // 4) save the User!
         $login = new Login();
         $person = new Person();
         $login->setUserId($user->getUserId());
         $login->setAccessLevel($user->getAccessLevel());
         $login->setPassword($user->getPassword());
         $person->setUserId($user->getUserId());
         $person->setUserType($user->getUserType());
         $person->setName($user->getName());
         $person->setAddress($user->getAddress());
         $person->setContactNo($user->getContactNo());
         $person->setNicNo($user->getNicNo());
         $em = $this->getDoctrine()->getManager();
         $em->persist($login);
         $em->persist($person);
         $em->flush();
         $this->get('session')->getFlashBag()->add('submit-notice', 'Your enquiry was successfully sent. Thank you!');
         // ... do any other work - like send them an email, etc
         // maybe set a "flash" success message for the user
         return $this->redirectToRoute('admin_addUser');
     }
     return $this->render('URMSAppBundle:Admin:adduser.html.twig', array('form' => $form->createView()));
 }
コード例 #2
0
 /**
  * Loads the user for the given username.
  *
  * This method must return null if the user is not found.
  *
  * @param string $username The username
  *
  * @return UserInterface|null
  */
 public function loadUserByUsername($username)
 {
     $query = "select l.User_Id,l.Password,u.role from login l,user_role u where l.user_role=u.Id and l.User_Id=:username";
     $Db = new Database();
     $Con = $Db->getDbConnection();
     $stmt = $Con->prepare($query);
     $stmt->execute(array(':username' => $username));
     $table = $stmt->fetch();
     if ($table['User_Id'] === null) {
         $message = sprintf('Username or Password Incorrect');
         throw new UsernameNotFoundException($message);
     }
     $user = new Login();
     $user->setUserId($table['User_Id']);
     $user->setPassword($table['Password']);
     $user->setRole($table['role']);
     return $user;
 }