Пример #1
0
 public function before()
 {
     if ($this->request->action() == 'login') {
         $this->_login_route = NULL;
     }
     parent::before();
 }
Пример #2
0
 function before()
 {
     parent::before();
     $this->company = Kohana::config('company');
     if ($this->view instanceof View) {
         $this->view->bind_global('company', $this->company);
     }
 }
 /**
  * INIT
  */
 public function init()
 {
     // call parent before
     parent::init();
     //create settings
     //read from website specific settings before general settings
     $this->_settings = Settings::factory($this->_controller, array('settings' . DIRECTORY_SEPARATOR . $this->_website . DIRECTORY_SEPARATOR, 'settings'));
     // set up listeners
     $this->listeners();
     // set up navigation
     if (Request::current()->is_initial() === TRUE) {
         $navigation = Viewer::instance('Navigation');
         $navigation->breadcrumb(Text::instance()->get('section.start'), URL::to('Start'));
         $navigation->breadcrumb(Text::instance()->get('module.name'), URL::to($this->_controller));
         $navigation->title(Text::instance()->get('title.' . $this->_action));
     }
 }
Пример #4
0
require_once '../application/controllers/auth.php';
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Регестрация</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
  </head>

  <body>
    <div style=" padding-top: 40px; padding-bottom: 40px;" class="container">
      <?php 
if (Controller_Auth::isAuthorized() and $_SESSION['group'] != 2) {
    ?>
      <h1>Добро пожаловать, вы уже зарегистрированы!</h1>
      <form class="ajax" method="post" action="ajax">
          <input type="hidden" name="act" value="logout">
          <div class="form-actions">
              <button class="btn btn-large btn-primary" type="submit">Выйти</button>
          </div>
      </form>

      <?php 
} else {
    ?>
      <form class="form-signin ajax" method="post" action="ajax">
        <div class="main-error alert alert-error hide"></div>
        <div class="form-center">
Пример #5
0
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Войти</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<body>

<div style="padding-top: 40px; padding-bottom: 40px;" class="container">

    <?php 
if (Controller_Auth::isAuthorized()) {
    ?>
        <h1>Добро пожаловать, вы авторизованы!</h1>
        <form class="ajax" method="post" action="ajax">
            <input type="hidden" name="act" value="logout">
            <div class="form-actions">
                <button class="btn btn-large btn-primary" type="submit">Выйти</button>
            </div>
        </form>
    <?php 
} else {
    ?>
        <form class="form-signin ajax" method="post" action="ajax">
            <div  class="main-error alert alert-error hide"></div>
                <div class="form-center">
                    <h3 class="form-signin-heading">Пожалуйста, авторизуйтесь!</h3>
Пример #6
0
 public function register()
 {
     if ($_SERVER["REQUEST_METHOD"] !== "POST") {
         // Method Not Allowed
         http_response_code(405);
         header("Allow: POST");
         $this->setFieldError("main", "Method Not Allowed");
         return;
     }
     setcookie("sid", "");
     $username = $this->getRequestParam("username");
     $password1 = $this->getRequestParam("password1");
     $password2 = $this->getRequestParam("password2");
     $group = $this->getRequestParam("group");
     if (empty($username)) {
         $this->setFieldError("username", "Enter the username");
         return;
     }
     if (empty($password1)) {
         $this->setFieldError("password1", "Enter the password");
         return;
     }
     if (empty($password2)) {
         $this->setFieldError("password2", "Confirm the password");
         return;
     }
     if ($password1 !== $password2) {
         $this->setFieldError("password2", "Confirm password is not match");
         return;
     }
     $user = new Controller_Auth();
     try {
         $new_user_id = $user->create($username, $password1, $group);
     } catch (\Exception $e) {
         $this->setFieldError("username", $e->getMessage());
         return;
     }
     $user->authorize($username, $password1);
     $this->message = sprintf("Hello, %s! Thank you for registration.", $username);
     $this->setResponse("redirect", "/");
     $this->status = "ok";
 }
Пример #7
0
 public function action_callback()
 {
     // Opauth can throw all kinds of nasty bits, so be prepared
     try {
         // get the Opauth object
         $opauth = \Auth_Opauth::forge(false);
         // and process the callback
         $status = $opauth->login_or_register();
         // fetch the provider name from the opauth response so we can display a message
         $provider = $opauth->get('auth.provider', '?');
         // deal with the result of the callback process
         switch ($status) {
             // a local user was logged-in, the provider has been linked to this user
             case 'linked':
                 // inform the user the link was succesfully made
                 // and set the redirect url for this status
                 Session::set('success', 'You have connected your ' . $provider . ' account!');
                 break;
                 // the provider was known and linked, the linked account as logged-in
             // the provider was known and linked, the linked account as logged-in
             case 'logged_in':
                 // inform the user the login using the provider was succesful
                 // and set the redirect url for this status
                 break;
                 // we don't know this provider login, ask the user to create a local account first
             // we don't know this provider login, ask the user to create a local account first
             case 'register':
                 // inform the user the login using the provider was succesful, but we need a local account to continue
                 // and set the redirect url for this status
                 switch ($provider) {
                     case 'Twitter':
                         $user_login = $opauth->get('auth.raw.screen_name');
                         $email = $opauth->get('auth.raw.screen_name') . '@twitter.com';
                         break;
                     case 'Google':
                         $user_login = str_replace('@gmail.com', '', $opauth->get('auth.raw.email'));
                         $email = $opauth->get('auth.raw.email');
                         break;
                     case 'Facebook':
                         $user_login = $opauth->get('auth.raw.username');
                         $email = $opauth->get('auth.raw.username') . '@facebook.com';
                         break;
                 }
                 // call Auth to create this user
                 $found_user = Model_User::query()->where('username', $user_login)->or_where('email', $email)->get_one();
                 if (empty($found_user) === false) {
                     if ($found_user->email == $email) {
                         // FORCE LOGIN AND REGISTER
                         Auth::force_login($found_user->id);
                     } else {
                         // Username already taken
                         Session::set('error', $user_login . ' , Username already taken, please register manually or try a differnt account');
                         Response::Redirect(Uri::Base());
                     }
                 } else {
                     $user_id = \Auth::create_user($user_login, md5($opauth->get('auth.credentials.token')), $email, \Config::get('application.user.default_group', 3), array('fullname' => $opauth->get('auth.info.name')));
                     Controller_Auth::Create_User($opauth, $user_id);
                 }
                 $opauth->login_or_register();
                 Session::set('success', 'You have connected your ' . $provider . ' account!');
                 break;
                 // we didn't know this provider login, but enough info was returned to auto-register the user
             // we didn't know this provider login, but enough info was returned to auto-register the user
             case 'registered':
                 // inform the user the login using the provider was succesful, and we created a local account
                 // and set the redirect url for this status
                 break;
             default:
                 throw new \FuelException('Auth_Opauth::login_or_register() has come up with a result that we dont know how to handle.');
         }
         // redirect to the url set
         \Response::redirect(Uri::Base());
     } catch (\OpauthException $e) {
         Session::set('error', ucfirst($e->getMessage()) . '!');
         \Response::redirect_back();
     } catch (\OpauthCancelException $e) {
         Session::set('error', 'Something went wrong!');
         \Response::redirect_back();
     }
 }