v1.0.0 (#183)
* #84 test data dump from CREST login * updated "credits" dialog (Google+ link) fixed login form layout * updated Cortex Data-Mapper * - #84 CREST Login (WIP) - New CREST controller - Database restructuring - improved type-casting for some controller functions - New login process - Fixed some bugs during the setup process (/setup root) - Added CREST request caching by response headers * pathfinder-84 [Feature Request] CREST Pilot Tracking, many smaller Bugfixes * pathfinder-84 [Feature Request] added develop JS files * closed #121 fixed wormhole signature type caching * closed #120 removed map-loading animation for larger maps (same behaviour as IGB) * closed #119 fixed wormhole signature id count * closed #114 Added check for already existing system when adding a new one. (fixed PDO 'duplicate entry' error) * closed #112 fixed DataTables error for missing "status" data (signature table) * closed #111 fixed convertDataToUTC(); client side date transformation * closed #109 fixed system TrueSec rounding * closed #103 fixed system updated timestamp in getData() * fixed CSS class for secStatus in Routes module * closed #121 fixed wormhole signature type caching * changed dateTime format from German to US format fixed some minor bugs in signatureTable module * closed #81 fixed "signature type" overwriting by "signature reader" update * closed #106 added new signature_types form C5/6 wormholes (gas/ore) * closed #129 fixed parameter hinting * closed #131 new "route search" algorithm, added current map systems to live search, added refresh/update functionality for each found route, added bulk route refresh function, added "meta map" route search (search on multiple maps), added route "filters" (restrict search on "stargates", "wormholes", "jumpbridges"), added route "filter" for wormholes (reduced/critical wormholes) closed #89 fixed "loop connections" on same system #84 added error messages for "invalid" CREST "Client ID" added "bootboxjs" (customized styled checkboxes/radio buttons) CSS only "Font Awesome" version upgrade 4.4.0 -> 4.61 "Bootbox.js" version upgrade 4.3.0 -> 4.4.0 fixed "system dialog" (added responsive layout) * closed #134 fixed db column type DT_INT (8 bytes) to DT_BIGINT * closed #138 added new cookie based login * closed #137 fixed javascript errors on trying to establish an "invalid" connection * - #84, #138 improved "character selection" on login page (expired cookies are deleted, character panel layout improvements) - added new "Server info panel" to the login page - added new cronjob to delete expired cookie authentication data * #138 enables character switching between characters which have same user * - PHP Framework upgrade 3.5.0 -> 3.5.1 (fixes some issues with CREST cURL caching, and SESSION management) - #138 added "cookie logout" to "logout" menu entry * - updated "feature page" with new feature descriptions and label - added some new images to the "feature gallery" - removed "beta" status from "magnetizing" feature on map menu - hide "server status" panel on "mobile" breakpoint * - #138 clear character authentication data on sold characters * closed #142 added custom "onsuspect()" session handler * #142 do not log suspect if no file is defined in pathfinder.ini * #142 added NullSec Data/Relic sites to C1/2/3 wormholes as signature option * #144 fixed "Character not found" warning * #144 fixed "Character not found" warning * closed #144 fixed broken routes panel in IGB * updated README.md for upcoming release * #147 response header validation * #149 changed comment for 'BASE' framework var * fixed map import * - added minimal SDE dump (EVE Online: Citadel) - #147 improved CREST API error logging (WIP) - improved SSO controller (removed access_token from public endpoints) * closed #154 added alliance maps to CREST API * - updated Gulp build dependencies - increased CREST timeout from 3s -> 4s - added "Accept" Headers for some CREST endpoints * cloased #147 * - closed #153 added character verification check for getAll(); Signatures Ajax endpoint * - updated README.md (added Slack developer chat information) * Bugfix frig holes (#159) * added missing frigate wormholes and fixed Q003 destination in shattered wormholes * changed C7 to 0.0 for Q003 * - fixed broken "graph" data for system * added a "failover" system for bad crest requests (HTTP status 5xx,.. ) * Red Gaint => Red Giant (#161) * closed #163 added CREST endpoint support for "waypoints" * fixed typo * closed #160 fixed tooltip container * - added new features to login page * closes #154 added alliance map support * fixed XML path for cronjobs * fixed a bug with inactive "private" maps * closes #175 added alternative environment configuration * - v1.0.0 build
This commit is contained in:
@@ -15,87 +15,109 @@ use DB;
|
||||
|
||||
class User extends Controller\Controller{
|
||||
|
||||
// captcha specific session keys
|
||||
const SESSION_CAPTCHA_ACCOUNT_UPDATE = 'SESSION.CAPTCHA.ACCOUNT.UPDATE';
|
||||
const SESSION_CAPTCHA_ACCOUNT_DELETE = 'SESSION.CAPTCHA.ACCOUNT.DELETE';
|
||||
|
||||
// user specific session keys
|
||||
const SESSION_KEY_USER = 'SESSION.USER';
|
||||
const SESSION_KEY_USER_ID = 'SESSION.USER.ID';
|
||||
const SESSION_KEY_USER_NAME = 'SESSION.USER.NAME';
|
||||
|
||||
// character specific session keys
|
||||
const SESSION_KEY_CHARACTER = 'SESSION.CHARACTER';
|
||||
const SESSION_KEY_CHARACTER_ID = 'SESSION.CHARACTER.ID';
|
||||
const SESSION_KEY_CHARACTER_NAME = 'SESSION.CHARACTER.NAME';
|
||||
const SESSION_KEY_CHARACTER_TIME = 'SESSION.CHARACTER.TIME';
|
||||
|
||||
const SESSION_KEY_CHARACTER_ACCESS_TOKEN = 'SESSION.CHARACTER.ACCESS_TOKEN';
|
||||
const SESSION_KEY_CHARACTER_REFRESH_TOKEN = 'SESSION.CHARACTER.REFRESH_TOKEN';
|
||||
|
||||
// log text
|
||||
const LOG_LOGGED_IN = 'userId: %s, userName: %s, charId: %s, charName: %s';
|
||||
|
||||
/**
|
||||
* valid reasons for captcha images
|
||||
* @var array
|
||||
* @var string array
|
||||
*/
|
||||
private static $captchaReason = ['createAccount', 'deleteAccount'];
|
||||
private static $captchaReason = [self::SESSION_CAPTCHA_ACCOUNT_UPDATE, self::SESSION_CAPTCHA_ACCOUNT_DELETE];
|
||||
|
||||
/**
|
||||
* login function
|
||||
* @param $f3
|
||||
* login a valid character
|
||||
* @param Model\CharacterModel $characterModel
|
||||
* @return bool
|
||||
*/
|
||||
public function logIn($f3){
|
||||
$data = $data = $f3->get('POST');
|
||||
protected function loginByCharacter(Model\CharacterModel &$characterModel){
|
||||
$login = false;
|
||||
|
||||
$return = (object) [];
|
||||
if($user = $characterModel->getUser()){
|
||||
// set user/character data to session -------------------
|
||||
$this->f3->set(self::SESSION_KEY_USER, [
|
||||
'ID' => $user->_id,
|
||||
'NAME' => $user->name
|
||||
]);
|
||||
|
||||
$user = null;
|
||||
$dateTime = new \DateTime();
|
||||
$this->f3->set(self::SESSION_KEY_CHARACTER, [
|
||||
'ID' => $characterModel->_id,
|
||||
'NAME' => $characterModel->name,
|
||||
'TIME' => $dateTime->getTimestamp()
|
||||
]);
|
||||
|
||||
if($data['loginData']){
|
||||
$loginData = $data['loginData'];
|
||||
$user = $this->logUserIn( $loginData['userName'], $loginData['userPassword'] );
|
||||
// save user login information ---------------------------
|
||||
$characterModel->touch('lastLogin');
|
||||
$characterModel->save();
|
||||
|
||||
// write login log --------------------------------------
|
||||
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.LOGIN') )->write(
|
||||
sprintf(self::LOG_LOGGED_IN,
|
||||
$user->_id,
|
||||
$user->name,
|
||||
$characterModel->_id,
|
||||
$characterModel->name
|
||||
)
|
||||
);
|
||||
|
||||
$login = true;
|
||||
}
|
||||
|
||||
// set "vague" error
|
||||
if(is_null($user)){
|
||||
$return->error = [];
|
||||
$loginError = (object) [];
|
||||
$loginError->type = 'login';
|
||||
$return->error[] = $loginError;
|
||||
}else{
|
||||
// update/check api data
|
||||
$user->updateApiData();
|
||||
return $login;
|
||||
}
|
||||
|
||||
// route user to map app
|
||||
$return->reroute = rtrim(self::getEnvironmentData('URL'), '/') . $f3->alias('map');
|
||||
/**
|
||||
* validate cookie character information
|
||||
* -> return character data (if valid)
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function getCookieCharacter($f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
if( !empty($data['cookie']) ){
|
||||
if( !empty($cookieData = $this->getCookieByName($data['cookie']) )){
|
||||
// cookie data is valid -> validate data against DB (security check!)
|
||||
if( !empty($characters = $this->getCookieCharacters(array_slice($cookieData, 0, 1, true))) ){
|
||||
// character is valid and allowed to login
|
||||
$return->character = reset($characters)->getData();
|
||||
}else{
|
||||
$characterError = (object) [];
|
||||
$characterError->type = 'warning';
|
||||
$characterError->message = 'This can happen through "invalid cookie data", "login restrictions", "CREST problems".';
|
||||
$return->error[] = $characterError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* core function for user login
|
||||
* @param $userName
|
||||
* @param $password
|
||||
* @return Model\UserModel|null
|
||||
*/
|
||||
private function logUserIn($userName, $password){
|
||||
|
||||
// try to verify user
|
||||
$user = $this->_verifyUser($userName, $password);
|
||||
|
||||
if( !is_null($user)){
|
||||
// user is verified -> ready for login
|
||||
|
||||
// set Session login
|
||||
$dateTime = new \DateTime();
|
||||
|
||||
$this->f3->set('SESSION.user', [
|
||||
'time' => $dateTime->getTimestamp(),
|
||||
'name' => $user->name,
|
||||
'id' => $user->id
|
||||
]);
|
||||
|
||||
// save user login information
|
||||
$user->touch('lastLogin');
|
||||
$user->save();
|
||||
|
||||
// save log
|
||||
$logText = "id: %s, name: %s, ip: %s";
|
||||
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.LOGIN') )->write(
|
||||
sprintf($logText, $user->id, $user->name, $this->f3->get('IP'))
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* get captcha image and store key to session
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function getCaptcha($f3){
|
||||
public function getCaptcha(\Base $f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
@@ -117,7 +139,7 @@ class User extends Controller\Controller{
|
||||
'fonts/oxygen-bold-webfont.ttf',
|
||||
14,
|
||||
6,
|
||||
'SESSION.' . $reason,
|
||||
$reason,
|
||||
'',
|
||||
$colorText,
|
||||
$colorBG
|
||||
@@ -136,337 +158,132 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* delete the character log entry for the current active (main) character
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function deleteLog($f3){
|
||||
|
||||
$user = $this->_getUser();
|
||||
if($user){
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
if($activeUserCharacter){
|
||||
$character = $activeUserCharacter->getCharacter();
|
||||
|
||||
if($characterLog = $character->getLog()){
|
||||
$characterLog->erase();
|
||||
}
|
||||
public function deleteLog(\Base $f3){
|
||||
$activeCharacter = $this->getCharacter();
|
||||
if($activeCharacter){
|
||||
if($characterLog = $activeCharacter->getLog()){
|
||||
$characterLog->erase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* log the current user out + clear character system log data
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function logOut($f3){
|
||||
public function logout(\Base $f3){
|
||||
$this->deleteLog($f3);
|
||||
parent::logOut($f3);
|
||||
parent::logout($f3);
|
||||
}
|
||||
|
||||
/**
|
||||
* save/update "map sharing" configurations for all map types
|
||||
* the user has access to
|
||||
* @param $f3
|
||||
* update user account data
|
||||
* -> a fresh user automatically generated on first login with a new character
|
||||
* -> see CREST SSO login
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function saveSharingConfig($f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
|
||||
$privateSharing = 0;
|
||||
$corporationSharing = 0;
|
||||
$allianceSharing = 0;
|
||||
|
||||
$user = $this->_getUser();
|
||||
|
||||
if($user){
|
||||
|
||||
// form values
|
||||
if(isset($data['formData'])){
|
||||
$formData = $data['formData'];
|
||||
|
||||
if(isset($formData['privateSharing'])){
|
||||
$privateSharing = 1;
|
||||
}
|
||||
|
||||
if(isset($formData['corporationSharing'])){
|
||||
$corporationSharing = 1;
|
||||
}
|
||||
|
||||
if(isset($formData['allianceSharing'])){
|
||||
$allianceSharing = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$user->shared = $privateSharing;
|
||||
$user->save();
|
||||
|
||||
// update corp/ally ---------------------------------------------------------------
|
||||
|
||||
$activeUserCharacter = $user->getActiveUserCharacter();
|
||||
|
||||
if(is_object($activeUserCharacter)){
|
||||
$corporation = $activeUserCharacter->getCharacter()->getCorporation();
|
||||
$alliance = $activeUserCharacter->getCharacter()->getAlliance();
|
||||
|
||||
if(is_object($corporation)){
|
||||
$corporation->shared = $corporationSharing;
|
||||
$corporation->save();
|
||||
}
|
||||
|
||||
if(is_object($alliance)){
|
||||
$alliance->shared = $allianceSharing;
|
||||
$alliance->save();
|
||||
}
|
||||
}
|
||||
|
||||
$return->userData = $user->getData();
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* search for a registration key model
|
||||
* e.g. for new user registration with "invite" feature enabled
|
||||
* @param $email
|
||||
* @param $registrationKey
|
||||
* @return bool|Model\RegistrationKeyModel
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getRegistrationKey($email, $registrationKey){
|
||||
$registrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
|
||||
$registrationKeyModel->load([
|
||||
'registrationKey = :registrationKey AND
|
||||
email = :email AND
|
||||
used = 0 AND
|
||||
active = 1',
|
||||
':registrationKey' => $registrationKey,
|
||||
':email' => $email
|
||||
]);
|
||||
|
||||
if( $registrationKeyModel->dry() ){
|
||||
return false;
|
||||
}else{
|
||||
return $registrationKeyModel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if there is already an active Key for a mail
|
||||
* @param $email
|
||||
* @param bool|false $used
|
||||
* @return bool|null
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function findRegistrationKey($email, $used = false){
|
||||
|
||||
$queryPart = 'email = :email AND active = 1';
|
||||
|
||||
if(is_int($used)){
|
||||
$queryPart .= ' AND used = ' . $used;
|
||||
}
|
||||
|
||||
$registrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
|
||||
$registrationKeyModels = $registrationKeyModel->find([
|
||||
$queryPart,
|
||||
':email' => $email
|
||||
]);
|
||||
|
||||
if( is_object($registrationKeyModels) ){
|
||||
return $registrationKeyModels;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* save/update user account data
|
||||
* @param $f3
|
||||
*/
|
||||
public function saveAccount($f3){
|
||||
public function saveAccount(\Base $f3){
|
||||
$data = $f3->get('POST');
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
|
||||
$captcha = $f3->get('SESSION.createAccount');
|
||||
$captcha = $f3->get(self::SESSION_CAPTCHA_ACCOUNT_UPDATE);
|
||||
|
||||
// reset captcha -> forces user to enter new one
|
||||
$f3->clear('SESSION.createAccount');
|
||||
$f3->clear(self::SESSION_CAPTCHA_ACCOUNT_UPDATE);
|
||||
|
||||
$newUserData = null;
|
||||
|
||||
// check for new user
|
||||
$loginAfterSave = false;
|
||||
|
||||
// valid registration key Model is required for new registration
|
||||
// if "invite" feature is enabled
|
||||
$registrationKeyModel = false;
|
||||
|
||||
if( isset($data['settingsData']) ){
|
||||
$settingsData = $data['settingsData'];
|
||||
if( isset($data['formData']) ){
|
||||
$formData = $data['formData'];
|
||||
|
||||
try{
|
||||
$user = $this->_getUser(0);
|
||||
if($activeCharacter = $this->getCharacter(0)){
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
// captcha is send -> check captcha
|
||||
if(
|
||||
isset($settingsData['captcha']) &&
|
||||
!empty($settingsData['captcha'])
|
||||
){
|
||||
|
||||
|
||||
if($settingsData['captcha'] === $captcha){
|
||||
// change/set sensitive user data requires captcha!
|
||||
|
||||
if($user === false){
|
||||
|
||||
// check if registration key invite function is enabled
|
||||
if($f3->get('PATHFINDER.REGISTRATION.INVITE') === 1 ){
|
||||
$registrationKeyModel = $this->getRegistrationKey( $settingsData['email'], $settingsData['registrationKey'] );
|
||||
|
||||
if($registrationKeyModel === false){
|
||||
throw new Exception\RegistrationException('Registration key invalid', 'registrationKey');
|
||||
}
|
||||
}
|
||||
|
||||
// new user registration
|
||||
$user = $mapType = Model\BasicModel::getNew('UserModel');
|
||||
$loginAfterSave = true;
|
||||
// captcha is send -> check captcha ---------------------------------
|
||||
if(
|
||||
isset($formData['captcha']) &&
|
||||
!empty($formData['captcha'])
|
||||
){
|
||||
if($formData['captcha'] === $captcha){
|
||||
// change/set sensitive user data requires captcha!
|
||||
|
||||
// set username
|
||||
if(
|
||||
isset($settingsData['name']) &&
|
||||
!empty($settingsData['name'])
|
||||
isset($formData['name']) &&
|
||||
!empty($formData['name'])
|
||||
){
|
||||
$user->name = $settingsData['name'];
|
||||
}
|
||||
}
|
||||
|
||||
// change/set email
|
||||
if(
|
||||
isset($settingsData['email']) &&
|
||||
isset($settingsData['email_confirm']) &&
|
||||
!empty($settingsData['email']) &&
|
||||
!empty($settingsData['email_confirm']) &&
|
||||
$settingsData['email'] == $settingsData['email_confirm']
|
||||
){
|
||||
$user->email = $settingsData['email'];
|
||||
}
|
||||
|
||||
// change/set password
|
||||
if(
|
||||
isset($settingsData['password']) &&
|
||||
isset($settingsData['password_confirm']) &&
|
||||
!empty($settingsData['password']) &&
|
||||
!empty($settingsData['password_confirm']) &&
|
||||
$settingsData['password'] == $settingsData['password_confirm']
|
||||
){
|
||||
$user->password = $settingsData['password'];
|
||||
}
|
||||
}else{
|
||||
// captcha was send but not valid -> return error
|
||||
$captchaError = (object) [];
|
||||
$captchaError->type = 'error';
|
||||
$captchaError->message = 'Captcha does not match';
|
||||
$return->error[] = $captchaError;
|
||||
}
|
||||
}
|
||||
|
||||
// saving additional user info requires valid user object (no captcha required)
|
||||
if($user){
|
||||
|
||||
// save API data
|
||||
if(
|
||||
isset($settingsData['keyId']) &&
|
||||
isset($settingsData['vCode']) &&
|
||||
is_array($settingsData['keyId']) &&
|
||||
is_array($settingsData['vCode'])
|
||||
){
|
||||
|
||||
// get all existing API models for this user
|
||||
$apiModels = $user->getAPIs();
|
||||
|
||||
foreach($settingsData['keyId'] as $i => $keyId){
|
||||
$api = null;
|
||||
|
||||
// search for existing API model
|
||||
foreach($apiModels as $key => $apiModel){
|
||||
if($apiModel->keyId == $keyId){
|
||||
$api = $apiModel;
|
||||
// make sure model is up2data -> cast()
|
||||
$api->cast();
|
||||
unset($apiModels[$key]);
|
||||
break;
|
||||
}
|
||||
$user->name = $formData['name'];
|
||||
}
|
||||
|
||||
if(is_null($api)){
|
||||
// new API Key
|
||||
$api = Model\BasicModel::getNew('UserApiModel');
|
||||
$api->userId = $user;
|
||||
// set email
|
||||
if(
|
||||
isset($formData['email']) &&
|
||||
isset($formData['email_confirm']) &&
|
||||
!empty($formData['email']) &&
|
||||
!empty($formData['email_confirm']) &&
|
||||
$formData['email'] == $formData['email_confirm']
|
||||
){
|
||||
$user->email = $formData['email'];
|
||||
}
|
||||
|
||||
$api->keyId = $keyId;
|
||||
$api->vCode = $settingsData['vCode'][$i];
|
||||
$api->save();
|
||||
// save/update user model
|
||||
// this will fail if model validation fails!
|
||||
$user->save();
|
||||
|
||||
$characterCount = $api->updateCharacters();
|
||||
}else{
|
||||
// captcha was send but not valid -> return error
|
||||
$captchaError = (object) [];
|
||||
$captchaError->type = 'error';
|
||||
$captchaError->message = 'Captcha does not match';
|
||||
$return->error[] = $captchaError;
|
||||
}
|
||||
}
|
||||
|
||||
if($characterCount == 0){
|
||||
// no characters found -> return warning
|
||||
$characterError = (object) [];
|
||||
$characterError->type = 'warning';
|
||||
$characterError->message = 'API verification failed. No Characters found for KeyId ' . $api->keyId;
|
||||
$return->error[] = $characterError;
|
||||
}
|
||||
// sharing config ---------------------------------------------------
|
||||
if(isset($formData['share'])){
|
||||
$privateSharing = 0;
|
||||
$corporationSharing = 0;
|
||||
$allianceSharing = 0;
|
||||
|
||||
if(isset($formData['privateSharing'])){
|
||||
$privateSharing = 1;
|
||||
}
|
||||
|
||||
// delete API models that no longer exists
|
||||
foreach($apiModels as $apiModel){
|
||||
$apiModel->delete();
|
||||
if(isset($formData['corporationSharing'])){
|
||||
$corporationSharing = 1;
|
||||
}
|
||||
|
||||
// get fresh updated user object (API info may have has changed)
|
||||
$user = $this->_getUser(0);
|
||||
}
|
||||
if(isset($formData['allianceSharing'])){
|
||||
$allianceSharing = 1;
|
||||
}
|
||||
|
||||
// set main character
|
||||
if( isset($settingsData['mainCharacterId']) ){
|
||||
$user->setMainCharacterId((int)$settingsData['mainCharacterId']);
|
||||
}
|
||||
// update private/corp/ally
|
||||
$corporation = $activeCharacter->getCorporation();
|
||||
$alliance = $activeCharacter->getAlliance();
|
||||
|
||||
// check if the user already has a main character
|
||||
// if not -> save the next best character as main
|
||||
$mainUserCharacter = $user->getMainUserCharacter();
|
||||
if(is_object($corporation)){
|
||||
$corporation->shared = $corporationSharing;
|
||||
$corporation->save();
|
||||
}
|
||||
|
||||
// set main character if no main character exists
|
||||
if(is_null($mainUserCharacter)){
|
||||
$user->setMainCharacterId();
|
||||
}
|
||||
if(is_object($alliance)){
|
||||
$alliance->shared = $allianceSharing;
|
||||
$alliance->save();
|
||||
}
|
||||
|
||||
// save/update user model
|
||||
// this will fail if model validation fails!
|
||||
$user->save();
|
||||
|
||||
if(is_object($registrationKeyModel)){
|
||||
$registrationKeyModel->used = 1;
|
||||
$registrationKeyModel->save();
|
||||
}
|
||||
|
||||
// log user in (in case he is new
|
||||
if($loginAfterSave){
|
||||
$this->logUserIn( $user->name, $settingsData['password'] );
|
||||
|
||||
// return reroute path
|
||||
$return->reroute = rtrim(self::getEnvironmentData('URL'), '/') . $this->f3->alias('map');
|
||||
$activeCharacter->shared = $privateSharing;
|
||||
$activeCharacter->save();
|
||||
}
|
||||
|
||||
// get fresh updated user object
|
||||
$user = $this->_getUser(0);
|
||||
$newUserData = $user->getData();
|
||||
}
|
||||
|
||||
}catch(Exception\ValidationException $e){
|
||||
$validationError = (object) [];
|
||||
$validationError->type = 'error';
|
||||
@@ -483,109 +300,6 @@ class User extends Controller\Controller{
|
||||
|
||||
// return new/updated user data
|
||||
$return->userData = $newUserData;
|
||||
|
||||
}
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* send mail with registration key
|
||||
* -> check INVITE in pathfinder.ini
|
||||
* @param $f3
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendInvite($f3){
|
||||
$data = $f3->get('POST.settingsData');
|
||||
$return = (object) [];
|
||||
|
||||
// check invite limit
|
||||
// get handed out key count
|
||||
$tempRegistrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
|
||||
$tempRegistrationKeyModels = $tempRegistrationKeyModel->find([ '
|
||||
email != "" AND
|
||||
active = 1'
|
||||
]);
|
||||
|
||||
$totalKeys = 0;
|
||||
if(is_object($tempRegistrationKeyModels)){
|
||||
$totalKeys = $tempRegistrationKeyModels->count();
|
||||
}
|
||||
|
||||
if(
|
||||
$f3->get('PATHFINDER.REGISTRATION.INVITE') == 1 &&
|
||||
$totalKeys < $f3->get('PATHFINDER.REGISTRATION.INVITE_LIMIT')
|
||||
){
|
||||
// key limit not reached
|
||||
|
||||
if(
|
||||
isset($data['email']) &&
|
||||
!empty($data['email'])
|
||||
){
|
||||
$email = trim($data['email']);
|
||||
|
||||
// check if mail is valid
|
||||
if( \Audit::instance()->email($email) ){
|
||||
|
||||
// new key for this mail is allowed
|
||||
$registrationKeyModel = $this->findRegistrationKey($email, 0);
|
||||
|
||||
if($registrationKeyModel === false){
|
||||
|
||||
// check for total number of invites (active and inactive) -> prevent spamming
|
||||
$allRegistrationKeysByMail = $this->findRegistrationKey($email);
|
||||
|
||||
if(
|
||||
$allRegistrationKeysByMail == false ||
|
||||
$allRegistrationKeysByMail->count() < 3
|
||||
){
|
||||
|
||||
// get a fresh key
|
||||
$registrationKeyModel = Model\BasicModel::getNew('RegistrationKeyModel');
|
||||
$registrationKeyModel->load(['
|
||||
used = 0 AND
|
||||
active = 1 AND
|
||||
email = "" ',
|
||||
':email' => $email
|
||||
], ['limit' => 1]);
|
||||
|
||||
}else{
|
||||
$validationError = (object) [];
|
||||
$validationError->type = 'warning';
|
||||
$validationError->message = 'The number of keys is limited by Email. You can not get more keys';
|
||||
$return->error[] = $validationError;
|
||||
}
|
||||
|
||||
}else{
|
||||
$registrationKeyModel = $registrationKeyModel[0];
|
||||
}
|
||||
|
||||
// send "old" key again or send a new key
|
||||
if( is_object($registrationKeyModel) ){
|
||||
$msg = 'Your personal Registration Key: ' . $registrationKeyModel->registrationKey;
|
||||
|
||||
$mailController = new MailController();
|
||||
$status = $mailController->sendInviteKey($email, $msg);
|
||||
|
||||
if( $status ){
|
||||
$registrationKeyModel->email = $email;
|
||||
$registrationKeyModel->ip = $this->f3->get('IP');
|
||||
$registrationKeyModel->save();
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$validationError = (object) [];
|
||||
$validationError->type = 'error';
|
||||
$validationError->field = 'email';
|
||||
$validationError->message = 'Email is not valid';
|
||||
$return->error[] = $validationError;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$validationError = (object) [];
|
||||
$validationError->type = 'warning';
|
||||
$validationError->message = 'The pool of beta keys has been exhausted, please try again in a few days/weeks';
|
||||
$return->error[] = $validationError;
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
@@ -593,31 +307,26 @@ class User extends Controller\Controller{
|
||||
|
||||
/**
|
||||
* delete current user account from DB
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function deleteAccount($f3){
|
||||
public function deleteAccount(\Base $f3){
|
||||
$data = $f3->get('POST.formData');
|
||||
$return = (object) [];
|
||||
|
||||
$captcha = $f3->get('SESSION.deleteAccount');
|
||||
$captcha = $f3->get(self::SESSION_CAPTCHA_ACCOUNT_DELETE);
|
||||
|
||||
// reset captcha -> forces user to enter new one
|
||||
$f3->clear('SESSION.deleteAccount');
|
||||
$f3->clear(self::SESSION_CAPTCHA_ACCOUNT_DELETE);
|
||||
|
||||
if(
|
||||
isset($data['captcha']) &&
|
||||
!empty($data['captcha']) &&
|
||||
$data['captcha'] === $captcha
|
||||
){
|
||||
$user = $this->_getUser(0);
|
||||
$activeCharacter = $this->getCharacter(0);
|
||||
$user = $activeCharacter->getUser();
|
||||
|
||||
$validUser = $this->_verifyUser( $user->name, $data['password']);
|
||||
|
||||
if(
|
||||
is_object($validUser) &&
|
||||
is_object($user) &&
|
||||
$user->id === $validUser->id
|
||||
){
|
||||
if($user){
|
||||
// send delete account mail
|
||||
$msg = 'Hello ' . $user->name . ',<br><br>';
|
||||
$msg .= 'your account data has been successfully deleted.';
|
||||
@@ -635,15 +344,9 @@ class User extends Controller\Controller{
|
||||
// remove user
|
||||
$user->erase();
|
||||
|
||||
$this->logOut($f3);
|
||||
$this->logout($f3);
|
||||
die();
|
||||
}
|
||||
}else{
|
||||
// password does not match current user pw
|
||||
$passwordError = (object) [];
|
||||
$passwordError->type = 'error';
|
||||
$passwordError->message = 'Invalid password';
|
||||
$return->error[] = $passwordError;
|
||||
}
|
||||
}else{
|
||||
// captcha not valid -> return error
|
||||
|
||||
Reference in New Issue
Block a user