Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> System CMS - Galeria
martinii007
post
Post #1





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 15.12.2011

Ostrzeżenie: (0%)
-----


Potrzebuję zmodyfikować kod w taki sposób, aby było można logować się bez potrzeby wpisywania haseł.

System jest obszerny, nie mniej jednak wybrałem chyba właściwy plik. Pytanie: Co zmienić by dostęp był aktywny bez wpisywania loginu i hasła. Próbowałem prawie wszystkiego, ale nic nie działa....

  1.  
  2. <?php
  3.  
  4. require_once 'DefaultController.class.php';
  5.  
  6. class MK_AccountController extends MK_DefaultController{
  7.  
  8. public function _init(){
  9. parent::_init();
  10. $this->getView()->setTemplatePath('small');
  11.  
  12. $user = MK_Authorizer::authorize();
  13. if( $user->isAuthorized() && MK_Request::getParam('section') !== 'log-out' )
  14. {
  15. $this->getView()->redirect(array('controller' => 'index'));
  16. }
  17. }
  18.  
  19. public function sectionIndex()
  20. {
  21. $this->getView()->setRender( false );
  22. $user = MK_Authorizer::authorize();
  23. if( !$user->isAuthorized() )
  24. {
  25. $this->getView()->redirect(array('controller' => 'account', 'section' => 'login'));
  26. }
  27. else
  28. {
  29. $this->getView()->redirect(array('controller' => 'index'));
  30. }
  31.  
  32. }
  33.  
  34. public function sectionLogin()
  35. {
  36. $config = MK_Config::getInstance();
  37.  
  38. $this->getView()->getHead()->prependTitle( 'Login' );
  39.  
  40. $form_structure = array(
  41. 'email' => array(
  42. 'label' => 'Email',
  43. 'validation' => array(
  44. 'instance' => array()
  45. )
  46. ),
  47. 'password' => array(
  48. 'label' => 'Password',
  49. 'validation' => array(
  50. 'instance' => array()
  51. ),
  52. 'attributes' => array(
  53. 'type' => 'password'
  54. )
  55. ),
  56. 'remember-me' => array(
  57. 'type' => 'checkbox',
  58. 'label' => 'Remember me on this machine'
  59. ),
  60. 'login' => array(
  61. 'type' => 'submit',
  62. 'attributes' => array(
  63. 'value' => 'Login'
  64. )
  65. ),
  66. 'forgot-password' => array(
  67. 'type' => 'link',
  68. 'text' => 'Forgot Pass',
  69. 'attributes' => array(
  70. 'href' => $this->getView()->uri(array('controller' => 'account', 'section' => 'forgot-password'))
  71. )
  72. )
  73. );
  74.  
  75. $form_settings = array(
  76. 'attributes' => array(
  77. 'class' => 'standard clear-fix small'
  78. )
  79. );
  80.  
  81. $form = new MK_Form($form_structure, $form_settings);
  82.  
  83. if($form->isSuccessful())
  84. {
  85. $user = MK_Authorizer::authorizeByEmailPass(
  86. $form->getField('email')->getValue(),
  87. $form->getField('password')->getValue()
  88. );
  89.  
  90. if( $user->isAuthorized() )
  91. {
  92. if( $user->objectGroup()->isAdmin() )
  93. {
  94. $cookie = MK_Cookie::getInstance();
  95. $session = MK_Session::getInstance();
  96. $session->login = $user->getId();
  97. if( $form->getField('remember-me')->getValue() )
  98. {
  99. $cookie->set('login', $user->getId(), $config->site->user_timeout);
  100. }
  101. $this->getView()->redirect( array('controller' => 'index') );
  102. }
  103. else
  104. {
  105. $form->getField('password')->getValidator()->addError("You cannot access this section");
  106. }
  107. }
  108. else
  109. {
  110. $form->getField('password')->getValidator()->addError("Incorrect email / password combination");
  111. }
  112. }
  113. $html = $form->render();
  114.  
  115. $this->view->login_form = $html;
  116.  
  117. }
  118.  
  119. public function sectionForgotPassword()
  120. {
  121. $config = MK_Config::getInstance();
  122.  
  123. $this->getView()->getHead()->prependTitle( 'Forgot Password' );
  124.  
  125. $html = '';
  126. $form_structure = array(
  127. 'email' => array(
  128. 'label' => 'Email',
  129. 'validation' => array(
  130. 'instance' => array(),
  131. 'email' => array()
  132. )
  133. ),
  134. 'reset-password' => array(
  135. 'type' => 'submit',
  136. 'attributes' => array(
  137. 'value' => 'Reset Password'
  138. )
  139. )
  140. );
  141.  
  142. $form_settings = array(
  143. 'attributes' => array(
  144. 'class' => 'small clear-fix standard'
  145. )
  146. );
  147.  
  148. $form = new MK_Form($form_structure, $form_settings);
  149.  
  150. if($form->isSuccessful()){
  151. $search_criteria = array(
  152. array('field' => 'email', 'value' => $form->getField('email')->getValue())
  153. );
  154.  
  155. $users_module = MK_RecordModuleManager::getFromSlug('users');
  156. $user_account = $users_module->searchRecords( $search_criteria );
  157. $user_account = array_pop($user_account);
  158.  
  159. if( $user_account ){
  160. $new_password = MK_Utility::getRandomPassword();
  161. $user_account
  162. ->setTemporaryPassword($new_password)
  163. ->save();
  164.  
  165. $message = '<p>Hi, <strong>'.$user_account->getDisplayName().'</strong>!</p><p>Your new login details are below;</p><p><strong>Email:</strong> '.$user_account->getEmail().'<br /><strong>Password:</strong> '.$new_password.'</p>';
  166. $emailer = new MK_BrandedEmail();
  167. $emailer
  168. ->setSubject('Password Recovery')
  169. ->setMessage($message);
  170.  
  171. if( !$emailer->send( $user_account->getEmail(), $user_account->getUsername()) )
  172. {
  173. $form->getField('email')
  174. ->getValidator()
  175. ->addError("There was a problem sending your login credentials. Please consult <a href=\"mailto:".$config->site->email."\">".$config->site->email."</a> stating your problem.");
  176. }
  177. else
  178. {
  179. $html .= '<p>An email containing login credentials has been sent to <strong>'.$user_account->getEmail().'</strong>!</p>';
  180. $html .= '<p>Upon receiving your new password you can <a href="'.$this->getView()->uri(array('controller' => 'account', 'section' => 'login')).'">login</a> and change it to something memorable.</p>';
  181. }
  182. }else{
  183. $form->getField('email')
  184. ->getValidator()
  185. ->addError("Invalid email");
  186. }
  187. }else{
  188. $html .= '<p>Forgotten your password? No worries, enter your email address below and we\'ll send you a new password. If you haven\'t forgotten your password the <a href="'.$this->getView()->uri(array('controller' => 'account', 'section' => 'login')).'">login</a>.</p>';
  189. }
  190. $html .= $form->render();
  191.  
  192. $this->view->password_reset_form = $html;
  193.  
  194. }
  195.  
  196. public function sectionLogOut()
  197. {
  198. $session = MK_Session::getInstance();
  199. $cookie = MK_Cookie::getInstance();
  200. unset($session->login, $cookie->login);
  201. $this->getView()->redirect(array('controller' => 'account', 'section' => 'login'));
  202. }
  203.  
  204. }
  205.  
  206. ?>
  207.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 08:00