Make subscription work
This commit is contained in:
@@ -91,7 +91,7 @@
|
|||||||
"invalid_email": "It doesn't look like an email",
|
"invalid_email": "It doesn't look like an email",
|
||||||
"subscribe": "Subscribe",
|
"subscribe": "Subscribe",
|
||||||
"subscribed": "Thanks! You'll receive a confirmation email shortly",
|
"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!",
|
"title": "Keep in touch!",
|
||||||
"unknown_email": "Unknown email address",
|
"unknown_email": "Unknown email address",
|
||||||
"unsubscribe": "Unsubscribe",
|
"unsubscribe": "Unsubscribe",
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ class Spot extends Main
|
|||||||
$asUserInfo = $this->oUser->getUserInfo();
|
$asUserInfo = $this->oUser->getUserInfo();
|
||||||
|
|
||||||
//Send Confirmation Email
|
//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 = new Email($this->asContext['serv_name'], 'email.confirmation');
|
||||||
$oConfEmail->setDestInfo($asUserInfo);
|
$oConfEmail->setDestInfo($asUserInfo);
|
||||||
$oConfEmail->send();
|
$oConfEmail->send();
|
||||||
@@ -348,7 +348,7 @@ class Spot extends Main
|
|||||||
|
|
||||||
public function unsubscribe() {
|
public function unsubscribe() {
|
||||||
$asResult = $this->oUser->removeUser();
|
$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) {
|
public function unsubscribeFromEmail($iUserId) {
|
||||||
|
|||||||
22
lib/User.php
22
lib/User.php
@@ -21,6 +21,17 @@ class User extends PhpObject {
|
|||||||
const COOKIE_ID_USER = 'subscriber';
|
const COOKIE_ID_USER = 'subscriber';
|
||||||
const COOKIE_DURATION = 60 * 60 * 24 * 365; //1 year
|
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
|
* Database Handle
|
||||||
* @var Db
|
* @var Db
|
||||||
@@ -35,16 +46,7 @@ class User extends PhpObject {
|
|||||||
parent::__construct(__CLASS__);
|
parent::__construct(__CLASS__);
|
||||||
$this->oDb = &$oDb;
|
$this->oDb = &$oDb;
|
||||||
$this->setUserId(0);
|
$this->setUserId(0);
|
||||||
$this->asUserInfo = array(
|
$this->asUserInfo = self::DEFAULT_USER;
|
||||||
'id' => 0,
|
|
||||||
Db::getId(self::USER_TABLE) => 0,
|
|
||||||
'name' => '',
|
|
||||||
'email' => '',
|
|
||||||
'language' => '',
|
|
||||||
'timezone' => '',
|
|
||||||
'active' => self::USER_INACTIVE,
|
|
||||||
'clearance' => self::CLEARANCE_USER
|
|
||||||
);
|
|
||||||
$this->checkUserCookie();
|
$this->checkUserCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import Api from '@scripts/api';
|
|||||||
import Lang from '@scripts/lang';
|
import Lang from '@scripts/lang';
|
||||||
import Projects from '@scripts/projects';
|
import Projects from '@scripts/projects';
|
||||||
import User from '@scripts/user';
|
import User from '@scripts/user';
|
||||||
import { createApp } from 'vue';
|
import { createApp, reactive } from 'vue';
|
||||||
|
|
||||||
//Main template
|
//Main template
|
||||||
import Spot from './Spot';
|
import Spot from './Spot';
|
||||||
@@ -16,7 +16,7 @@ const appConfig = JSON.parse(document.getElementById('app-config').textContent);
|
|||||||
|
|
||||||
//Instances
|
//Instances
|
||||||
const oProjects = new Projects(appConfig.projects);
|
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 oLang = new Lang({translations: appConfig.consts.lang, prefix: appConfig.consts.lang_prefix});
|
||||||
const oApi = new Api({
|
const oApi = new Api({
|
||||||
server: appConfig.consts.server,
|
server: appConfig.consts.server,
|
||||||
|
|||||||
@@ -511,15 +511,21 @@ export default {
|
|||||||
}).text(asInfo.lat_dms+' '+asInfo.lon_dms);
|
}).text(asInfo.lat_dms+' '+asInfo.lon_dms);
|
||||||
},
|
},
|
||||||
async manageSubs() {
|
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,}))$/;
|
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')});
|
if(!regexEmail.test(this.user.email)) this.nlFeedbacks.push({type:'error', 'msg':this.lang.get('newsletter.invalid_email')});
|
||||||
else {
|
else {
|
||||||
this.api.get(this.nlAction, {'email': this.user.email, 'name': this.user.name})
|
const sAction = this.nlAction;
|
||||||
.then((asUser, sDesc) => {
|
this.nlLoading = true;
|
||||||
this.nlFeedbacks.push('success', sDesc);
|
|
||||||
Object.assign(this.user, asUser);
|
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) {
|
toggleFeedPanel(bShow, sMapAction) {
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ export default class Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async get(action, params = {}) {
|
async get(action, params = {}) {
|
||||||
|
const response = await this.request(action, params);
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async request(action, params = {}) {
|
||||||
const requestParams = {
|
const requestParams = {
|
||||||
...params,
|
...params,
|
||||||
a: action,
|
a: action,
|
||||||
@@ -34,6 +39,6 @@ export default class Api {
|
|||||||
throw response.desc;
|
throw response.desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.data;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
export default class User {
|
export default class User {
|
||||||
|
|
||||||
constructor(asUserInfo = {}, sDefaultTimeZone = '') {
|
constructor(asUserInfo = {}, sDefaultTimeZone = '') {
|
||||||
Object.assign(this, asUserInfo);
|
this.setInfo(asUserInfo);
|
||||||
this.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.timezone || sDefaultTimeZone;
|
this.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.timezone || sDefaultTimeZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInfo(asUserInfo = {}) {
|
||||||
|
Object.assign(this, asUserInfo);
|
||||||
|
}
|
||||||
|
|
||||||
hasClearance(sClearance) {
|
hasClearance(sClearance) {
|
||||||
return this.clearance >= sClearance;
|
return this.clearance >= sClearance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,8 @@
|
|||||||
&.loading {
|
&.loading {
|
||||||
background-color: color.$message;
|
background-color: color.$message;
|
||||||
color: color.$post-input-bg;
|
color: color.$post-input-bg;
|
||||||
span {
|
|
||||||
|
.spot-icon {
|
||||||
@extend .flicker;
|
@extend .flicker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user