Skip to content

Commit

Permalink
v.0.1-beta [Версия для тестирования]
Browse files Browse the repository at this point in the history
Базовые функции модуля.
  • Loading branch information
skysilver-lab committed Jun 9, 2019
1 parent 23b6902 commit 98fc276
Show file tree
Hide file tree
Showing 114 changed files with 16,125 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
installed
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# majordomo-yandexhome
Yandex smart home platform integration
# Yandex Home

Модуль поддержки **личных** (приватных) навыков для платформы умного дома **Яндекс**.
Binary file added img/modules/yandexhome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modules/yandexhome/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Options All -Indexes
138 changes: 138 additions & 0 deletions modules/yandexhome/authorize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

require_once ('server.php');

$request = OAuth2\Request::createFromGlobals();

// Пишем в лог входящий запрос.
$yandexhome->WriteLog($yandexhome->IncomingRequestFormat($request));

$response = new OAuth2\Response();

// Проверяем валидность запроса на авторизацию.
if (!$server->validateAuthorizeRequest($request, $response)) {
// Если не валиден, то отправляем ответ с ошибкой и завершаем работу.
$response->send();
$yandexhome->WriteLog('authorize.php >>> ' . $server->getResponse());
die;
}

$_SESSION['REQUEST_URI'] = $request->server['REQUEST_URI'];

$user_name = $yandexhome->config['USER_NAME'];
$user_pass = $yandexhome->config['USER_PASS'];

if (isset($_SESSION['user']) && $_SESSION['user'] == $user_name) {
$_SESSION['AUTH'] = true;
} else {
$_SESSION['AUTH'] = false;
}

$user = $_SESSION['AUTH'] ? $user_name : null;

$message = '';

if (!empty($_SESSION['message'])) {
$message = $_SESSION['message'];
unset($_SESSION['message']);
}

if ($_SESSION['AUTH'] && isset($_POST['authorized'])) {
$is_authorized = ($_POST['authorized'] === 'yes'); // Если yes, то true, иначе false.
$log = $server->handleAuthorizeRequest($request, $response, $is_authorized);
$response->send();
unset($_SESSION['user']);
session_destroy();
$yandexhome->WriteLog('authorize.php >>> ' . $log);
} else if (!$_SESSION['AUTH'] && isset($_POST['login']) && isset($_POST['password'])) {
// Если не авторизованы.
if(!empty($_POST['login']) && !empty($_POST['password']) && $user_name == $_POST['login']) {
// Если переданы логин/пароль, и пользователь с таким логином имеется в списке пользователей,
// то проверим корректность введенного пароля.
if($user_pass == $_POST['password']) {
// Пароль совпадает. Инициируем сессию.
$_SESSION['user'] = $_POST['login'];
$_SESSION['AUTH'] = true;
$user = $_SESSION['AUTH'] ? $user_name : null;
}
}
if(!isset($_SESSION['user']) || $_SESSION['user'] != $_POST['login']) {
// Авторизация не прошла. Сохраним ошибку.
$message = 'Неверный логин или пароль. Повторите попытку.';
}
}

?>

<html lang = "ru">

<head>
<meta charset = "UTF-8">
<title>MajorDoMo | Connect</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel = "stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel = "stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel = "stylesheet" href="css/style.css">
<meta name = "viewport" content="width=device-width, initial-scale=1">
</head>

<body class="login-page">

<?php

if($_SESSION['AUTH']) { //Если авторизованы ?>

<main>
<div class="login-block">
<div><img src="img/ylogo.png" alt="logo" width="100%"></div>
<h1>Здравствуйте, <?php echo $user; ?>!</h1>
<form method = "post">
<div>
Приложение <b>Yandex Home</b> запрашивает доступ к вашему аккаунту <b>MajorDoMo</b>, чтобы контролировать привязанные к нему устройства.
</div>
<br>
<div>
Предоставить доступ для <b>Yandex Home</b>?
</div>
<button class="btn btn-primary btn-block" type="submit" name="authorized" value="yes"><b>Предоставить</b></button>
<br>
<button class="btn btn-link" type="submit" name="authorized" value="no"><b>Отказать</b></button>
</form>
<h6>OAuth2 Client ID: <?php echo $request->query['client_id']; ?></h6>
</div>
</main>


<?php } else { //Если не авторизованы ?>

<main>
<div class="login-block">
<img src="img/mlogo.png" alt="logo">
<h1>Вход в аккаунт MajorDoMo</h1>
<form method = "post">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user ti-user"></i></span>
<input type="text" name = "login" class="form-control" placeholder="Логин">
</div>
</div>
<hr class="hr-xs">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock ti-unlock"></i></span>
<input type="password" name = "password" class="form-control" placeholder="Пароль">
</div>
</div>
<?php if (!empty($message)) { ?>
<p><?php echo $message; ?></p>
<?php } ?>
<button class="btn btn-primary btn-block" type="submit"><b>Войти</b></button>
</form>
</div>
</main>

<?php } ?>

</body>
</html>
197 changes: 197 additions & 0 deletions modules/yandexhome/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
.login-page
{
background-color:#e5e7ed
}
.login-page main
{
width:100%;
max-width:460px;
margin:8% auto 5%
}
.login-block
{
background-color:#fff;
padding-right:40px;
padding-left:40px;
padding-top:40px;
padding-bottom:30px;
-webkit-box-shadow:0 3px 50px 0 rgba(0,0,0,.1);
box-shadow:0 3px 50px 0 rgba(0,0,0,.1);
text-align:center;
border-radius:5px
}
.login-block h1,.login-block h6
{
font-family:Open Sans,sans-serif;
color:#96a2b2;
letter-spacing:1px
}
.login-block h1
{
font-size:22px;
margin-bottom:40px;
margin-top:40px
}
.login-block h6
{
font-size:11px;
text-transform:uppercase;
margin-top:0
}
.login-block .form-group
{
margin-top:15px;
margin-bottom:15px;
}
.login-block .form-control,.login-block .form-control:focus,.login-block .input-group-addon,.login-block .input-group-addon:focus
{
background-color:transparent;
border:none;
}
.login-block .form-control
{
font-size:17px;
border-radius:0px;
}
.login-block input:-webkit-autofill
{
-webkit-box-shadow:0 0 0 1000px #fff inset;
-webkit-text-fill-color:#818a91;
-webkit-transition:none;
-o-transition:none;
transition:none;
}
.login-block .input-group-addon
{
color:#29aafe;
font-size:19px;
opacity:.5
}
.login-block .btn-block
{
margin-top:30px;
padding:15px;
padding-top:10px;
padding-bottom:10px;
font-size:16px;
background:#29aafe;
border-color:#29aafe;
}
.login-block .hr-xs
{
margin-top:5px;
margin-bottom:5px
}
.login-footer
{
margin-top:60px;
opacity:.5;
-webkit-transition:opacity .3s ease-in-out;
-o-transition:opacity .3s ease-in-out;
transition:opacity .3s ease-in-out
}
.login-footer:hover
{
opacity:1
}
.login-links
{
padding:15px 5px 0;
font-size:13px;
color:#96a2b2
}
.login-links:after
{
content:'';
display:table;
clear:both
}
.login-links a
{
color:#96a2b2;
opacity:.9
}
.login-links a:hover
{
color:#29aafe;
opacity:1
}
@media (max-width:767px)
{
.login-page main
{
position:static;
top:auto;
left:auto;
-webkit-transform:none;
-o-transform:none;
transform:none;
padding:30px 15px
}
.login-block{padding:20px}}
.social-icons
{
padding-left:0;
margin-bottom:0;
list-style:none
}
.social-icons li
{
display:inline-block;
margin-bottom:4px
}
.social-icons li.title
{
margin-right:15px;
text-transform:uppercase;
color:#96a2b2;
font-weight:700;
font-size:13px
}
.social-icons a{
background-color:#eceeef;
color:#818a91;
font-size:16px;
display:inline-block;
line-height:44px;
width:44px;
height:44px;
text-align:center;
margin-right:8px;
border-radius:100%;
-webkit-transition:all .2s linear;
-o-transition:all .2s linear;
transition:all .2s linear
}
.social-icons a:active,.social-icons a:focus,.social-icons a:hover
{
color:#fff;
background-color:#29aafe
}
.social-icons.size-sm a
{
line-height:34px;
height:34px;
width:34px;
font-size:14px
}
.social-icons a.facebook:hover
{
background-color:#3b5998
}
.social-icons a.rss:hover
{
background-color:#f26522
}
.social-icons a.google-plus:hover
{
background-color:#dd4b39
}
.social-icons a.twitter:hover
{
background-color:#00aced
}
.social-icons a.linkedin:hover
{
background-color:#007bb6
}
Binary file added modules/yandexhome/favicon.ico
Binary file not shown.
Binary file added modules/yandexhome/img/mlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modules/yandexhome/img/ylogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions modules/yandexhome/lib/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
1 change: 1 addition & 0 deletions modules/yandexhome/lib/OAuth2/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
Loading

0 comments on commit 98fc276

Please sign in to comment.