[MODX, MIGX] Простейшая авторизация

Авторизация на сайте этим способом подойдет для тех случаев, когда есть какая-то закрытая страница, к примеру прайс лист. И у вы хотите иметь вохможность выдать логин и пароль каким-то конкретным персонам. При этом вам не нужно чтобы они сами регистрировались.

Доп. поле типа MIGX simpleMigxAuth

Быстро и просто его можно сформировать в генераторе MIGX. Главное чтобы там были поля: login и password.

Вкладки формы:

[
  {
    "caption": "Заголовок",
    "fields": [
      {
        "field": "login",
        "caption": "Логин",
        "inputTVtype": "text"
      },
      {
        "field": "password",
        "caption": "Пароль",
        "inputTVtype": "text"
      }
    ]
  }
]

Разметка колонок:

[{
  "header": "Логин",
  "dataIndex": "login"
},{
  "header": "Пароль",
  "dataIndex": "password"
}]

Сниппет simpleMigxAuth

$tvname     = isset($tvname) ? $tvname :"migx_simpleMigxAuth";
$tpl_form   = isset($tpl_form) ? $tpl_form :"simpleMigxAuth_form_tpl";
$tpl_exit   = isset($tpl_exit) ? $tpl_exit :"simpleMigxAuth_exit_tpl";

$error_array = array();
$return_data = false;

// SESSION EXIT
if(isset($_GET['sma_session_exit'])){
    unset($_SESSION['sma_login'],$_SESSION['sma_password']);
    $url = $modx->makeUrl($modx->resource->get('id'));
    $modx->sendRedirect($url);
}
// Session auth
if(!empty($_SESSION['sma_login']) && !empty($_SESSION['sma_password'])){
    $input_login = $_SESSION['sma_login'];
    $input_password = $_SESSION['sma_password'];
}else{
    // Form auth
    if(empty($_POST['login']) || empty($_POST['password'])){
        return $modx->getChunk($tpl_form);
    }else{
        $input_login = strtolower(strip_tags(trim($_POST['login'])));
        $input_password = strtolower(strip_tags(trim($_POST['password'])));
    }
}
// GET DATA FROM MIGX TV
$users_data = json_decode($modx->resource->getTVValue($tvname), true);

foreach($users_data as $v){
    if($v['login'] == $input_login AND $v['password'] == $input_password){
        $return_data = $modx->getChunk($tpl_exit).$modx->resource->get('content');
        if(!empty($_POST['userremember'])){
            $_SESSION['sma_login'] = $input_login;
            $_SESSION['sma_password'] = $input_password;
        }
    }else{
        //if($v['login'] == $input_login){$error_array["login_true"] = 1;}
        //if($v['password'] == $input_password){$error_array["password_true"] = 1;}
        $error_array["simpleMigxAuth_fail"] = 1;
    }
    if($return_data){
        break;
    }
}
if(!$return_data){
    unset($_SESSION['sma_login'],$_SESSION['sma_password']);
    $return_data = $modx->getChunk($tpl_form,$error_array);
}
return $return_data;

Вызов cниппета simpleMigxAuth

[[!simpleMigxAuth?
    &tvname=`migx_simpleMigxAuth`
    &tpl_form=`simpleMigxAuth_form_tpl`
    &tpl_exit=`simpleMigxAuth_exit_tpl`
]]

Чанк simpleMigxAuth_form_tpl

[[+simpleMigxAuth_fail:is=`1`:then=` <div class="simpleMigxAuth_empty"> Ошибка доступа! </div> `]]

Чанк simpleMigxAuth_exit_tpl

    

CSS

.simpleMigxAuth_form_input_wr{
	margin: 15px 0;
}
.simpleMigxAuth_form_input_wr input {
	width: 100%;
	padding: 15px 20px;
	height: 50px;
	border-radius: 3px;
	border: 3px solid #ededed;
	font-family: inherit;
	outline: none;
	font-size: 16px;
}
.simpleMigxAuth_form_input_wr input:focus {
	border: 3px solid #6dd286;
}
.simpleMigxAuth_form_submit{
	background-color: #2f2f2f;
	padding: 15px 20px;
	margin-top: 15px;
	border: none;
	border-radius: 3px;
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	letter-spacing: 0.5px;
	text-transform: uppercase;
	display: inline-block;
	font-family: inherit;
	cursor: pointer;
	outline: none;
}
.simpleMigxAuth_empty {
	margin-bottom: 15px;
	font-size: 18px;
	color: #ff3d00;
	font-weight: 600;
}
.simpleMigxAuth_exit{
    
}
.simpleMigxAuth_exit a{
	background-color: #2f2f2f;
	padding: 15px 20px;
	margin-top: 15px;
	margin-bottom: 15px;
	border: none;
	border-radius: 3px;
	color: #fff;
	font-size: 14px;
	font-weight: 600;
	text-decoration: none;
	letter-spacing: 0.5px;
	text-transform: uppercase;
	display: inline-block;
	font-family: inherit;
	cursor: pointer;
	outline: none;
}
.simpleMigxAuth_exit a:hover{
    color: #fff;
}

Комментарии (0)

  1. Напишите первый комментарий
*Комментарий будет опубликован после проверки модератором

Похожие статьи

Наш сайт использует куки, нажмите «ОК» если вы не против
OK