diff --git a/i18n/en.json b/i18n/en.json index afae8fe..6626847 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -91,7 +91,7 @@ "invalid_email": "It doesn't look like an email", "subscribe": "Subscribe", "subscribed": "Thanks! You'll receive a confirmation email shortly", - "subscribed_desc": "You're all set. We'll send you updates as soon as we get them", + "subscribed_desc": "You're all set. We'll send you updates as soon as we get them.", "title": "Keep in touch!", "unknown_email": "Unknown email address", "unsubscribe": "Unsubscribe", diff --git a/lib/Spot.php b/lib/Spot.php index fdb02cc..f87b703 100755 --- a/lib/Spot.php +++ b/lib/Spot.php @@ -337,7 +337,7 @@ class Spot extends Main $asUserInfo = $this->oUser->getUserInfo(); //Send Confirmation Email - if($asResult['result'] && $asResult['desc']=='lang:newsletter.subscribed') { + if($asResult['result'] && $asResult['desc']=='lang:newsletter.subscribed' && !Settings::DEBUG) { $oConfEmail = new Email($this->asContext['serv_name'], 'email.confirmation'); $oConfEmail->setDestInfo($asUserInfo); $oConfEmail->send(); @@ -348,7 +348,7 @@ class Spot extends Main public function unsubscribe() { $asResult = $this->oUser->removeUser(); - return self::getJsonResult($asResult['result'], $asResult['desc'], $asResult['data']); + return self::getJsonResult($asResult['result'], $asResult['desc'], User::DEFAULT_USER); } public function unsubscribeFromEmail($iUserId) { diff --git a/lib/User.php b/lib/User.php index 9ae04a3..c9ed1e9 100644 --- a/lib/User.php +++ b/lib/User.php @@ -21,6 +21,17 @@ class User extends PhpObject { const COOKIE_ID_USER = 'subscriber'; const COOKIE_DURATION = 60 * 60 * 24 * 365; //1 year + const DEFAULT_USER = array( + 'id' => 0, + 'id_user' => 0, + 'name' => '', + 'email' => '', + 'language' => '', + 'timezone' => '', + 'active' => self::USER_INACTIVE, + 'clearance' => self::CLEARANCE_USER + ); + /** * Database Handle * @var Db @@ -35,16 +46,7 @@ class User extends PhpObject { parent::__construct(__CLASS__); $this->oDb = &$oDb; $this->setUserId(0); - $this->asUserInfo = array( - 'id' => 0, - Db::getId(self::USER_TABLE) => 0, - 'name' => '', - 'email' => '', - 'language' => '', - 'timezone' => '', - 'active' => self::USER_INACTIVE, - 'clearance' => self::CLEARANCE_USER - ); + $this->asUserInfo = self::DEFAULT_USER; $this->checkUserCookie(); } diff --git a/src/app.js b/src/app.js index c0321a1..6d6d116 100644 --- a/src/app.js +++ b/src/app.js @@ -3,7 +3,7 @@ import Api from '@scripts/api'; import Lang from '@scripts/lang'; import Projects from '@scripts/projects'; import User from '@scripts/user'; -import { createApp } from 'vue'; +import { createApp, reactive } from 'vue'; //Main template import Spot from './Spot'; @@ -16,7 +16,7 @@ const appConfig = JSON.parse(document.getElementById('app-config').textContent); //Instances const oProjects = new Projects(appConfig.projects); -const oUser = new User(appConfig.user, appConfig.consts.default_timezone); +const oUser = reactive(new User(appConfig.user, appConfig.consts.default_timezone)); const oLang = new Lang({translations: appConfig.consts.lang, prefix: appConfig.consts.lang_prefix}); const oApi = new Api({ server: appConfig.consts.server, diff --git a/src/components/project.vue b/src/components/project.vue index ffd6e82..b8ac95f 100644 --- a/src/components/project.vue +++ b/src/components/project.vue @@ -511,15 +511,21 @@ export default { }).text(asInfo.lat_dms+' '+asInfo.lon_dms); }, async manageSubs() { + if(this.nlLoading) return; + var regexEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if(!regexEmail.test(this.user.email)) this.nlFeedbacks.push({type:'error', 'msg':this.lang.get('newsletter.invalid_email')}); else { - this.api.get(this.nlAction, {'email': this.user.email, 'name': this.user.name}) - .then((asUser, sDesc) => { - this.nlFeedbacks.push('success', sDesc); - Object.assign(this.user, asUser); + const sAction = this.nlAction; + this.nlLoading = true; + + this.api.request(sAction, {'email': this.user.email, 'name': this.user.name}) + .then((asResponse) => { + this.nlFeedbacks.push({type: asResponse.result, msg: asResponse.desc}); + this.user.setInfo(asResponse.data); }) - .catch((sDesc) => {this.nlFeedbacks.push('error', sDesc);}); + .catch((sDesc) => {this.nlFeedbacks.push({type:'error', msg:sDesc?.message || sDesc});}) + .finally(() => {this.nlLoading = false;}); } }, toggleFeedPanel(bShow, sMapAction) { diff --git a/src/scripts/api.js b/src/scripts/api.js index a405e94..90c2db2 100644 --- a/src/scripts/api.js +++ b/src/scripts/api.js @@ -9,6 +9,11 @@ export default class Api { } async get(action, params = {}) { + const response = await this.request(action, params); + return response.data; + } + + async request(action, params = {}) { const requestParams = { ...params, a: action, @@ -34,6 +39,6 @@ export default class Api { throw response.desc; } - return response.data; + return response; } } diff --git a/src/scripts/user.js b/src/scripts/user.js index 2b22cb9..71cb35f 100644 --- a/src/scripts/user.js +++ b/src/scripts/user.js @@ -1,10 +1,14 @@ export default class User { constructor(asUserInfo = {}, sDefaultTimeZone = '') { - Object.assign(this, asUserInfo); + this.setInfo(asUserInfo); this.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.timezone || sDefaultTimeZone; } + setInfo(asUserInfo = {}) { + Object.assign(this, asUserInfo); + } + hasClearance(sClearance) { return this.clearance >= sClearance; } diff --git a/src/styles/_page.project.settings.scss b/src/styles/_page.project.settings.scss index 5d83f64..2b36652 100644 --- a/src/styles/_page.project.settings.scss +++ b/src/styles/_page.project.settings.scss @@ -135,7 +135,8 @@ &.loading { background-color: color.$message; color: color.$post-input-bg; - span { + + .spot-icon { @extend .flicker; } }