83 lines
2.5 KiB
PHP
83 lines
2.5 KiB
PHP
|
|
<?
|
||
|
|
|
||
|
|
namespace controller\core\user\profile;
|
||
|
|
|
||
|
|
use ms\ms\structure\msControllerTable;
|
||
|
|
|
||
|
|
class Api extends msControllerTable {
|
||
|
|
static $class = '\profile';
|
||
|
|
function reg(){
|
||
|
|
$res = [];
|
||
|
|
if($portal = \Site::$portal) {
|
||
|
|
$res = \Profile::reg($_POST,\Site::$portal_id);
|
||
|
|
|
||
|
|
if($res->id && \Site::$theme){
|
||
|
|
\Site::$theme::sendEmailRegistration($res->id);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
function login(){
|
||
|
|
if($portal = \Site::$portal) {
|
||
|
|
echo je(\Profile::login($_POST['login'], $_POST['pass'],\Site::$portal_id));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
function updateMyPass(){
|
||
|
|
$res = 0;
|
||
|
|
if($portal = \Site::$portal and IF_PROFILE) {
|
||
|
|
$data = \Profile::$data;
|
||
|
|
$pass = \Profile::preparePass($_POST['pass1']);
|
||
|
|
if($pass) {
|
||
|
|
if($_POST['pass1']!=$_POST['pass2']){
|
||
|
|
$res = 4;
|
||
|
|
} else {
|
||
|
|
if($_POST['no_check_pass']){
|
||
|
|
\Profile::updateMyPass($data, $pass);
|
||
|
|
$res = 3;
|
||
|
|
} else {
|
||
|
|
if (\Profile::checkPassword($data, $_POST['pass'])) {
|
||
|
|
\Profile::updateMyPass($data, $pass);
|
||
|
|
$res = 3;
|
||
|
|
} else $res = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else $res = 2;
|
||
|
|
}
|
||
|
|
// 0 - не авторизован
|
||
|
|
// 1 - старый пароль не верный
|
||
|
|
// 2 - не прислан пароль
|
||
|
|
// 3 - успешно обновили
|
||
|
|
// 4 - пароли не совпадают
|
||
|
|
if($_POST['json']) echo je(['type'=>$res]);
|
||
|
|
else echo $res;
|
||
|
|
}
|
||
|
|
function updateMy(){
|
||
|
|
$res = [
|
||
|
|
'data'=>$_POST,
|
||
|
|
];
|
||
|
|
if($portal = \Site::$portal and IF_PROFILE) {
|
||
|
|
$val = $_POST;
|
||
|
|
if($c = $_POST['sname']) $val[\Profile::$SNAME] = $c;
|
||
|
|
if($c = $_POST['name']) $val[\Profile::$NAME] = $c;
|
||
|
|
if($c = $_POST['fname']) $val[\Profile::$FNAME] = $c;
|
||
|
|
if($c = $_POST['phone']) $val[\Profile::$PHONE] = $c;
|
||
|
|
if($c = $_POST['city']) $val[\Profile::$CITY] = $c;
|
||
|
|
if($c = $_POST['bdate']) $val[\Profile::$BDATE] = date('Y-m-d',strtotime($c));
|
||
|
|
|
||
|
|
if($val) {
|
||
|
|
\Profile::updateById(PID, $val);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
function exit(){
|
||
|
|
if($portal = \Site::$portal) {
|
||
|
|
\Profile::exit();
|
||
|
|
echo je(array());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|