validation
This commit is contained in:
parent
c3bb3fb22b
commit
68dd65cc7a
7 changed files with 50 additions and 18 deletions
|
@ -1,8 +1,9 @@
|
|||
# TODO
|
||||
|
||||
* Option in UI to add email without prompt
|
||||
* validation
|
||||
* a point to unsubscribe
|
||||
* stop the ui prompting if already subscribed
|
||||
* send actual emails with content
|
||||
*
|
||||
* Clean up all code
|
||||
|
||||
|
|
|
@ -10,3 +10,7 @@ exports.eejsBlock_toolbarRight = function (hook_name, args, cb) {
|
|||
return cb();
|
||||
};
|
||||
|
||||
exports.eejsBlock_embedPopup = function (hook_name, args, cb) {
|
||||
args.content = args.content + eejs.require("ep_email_notifications/templates/embedFrame.html", {}, module);
|
||||
return cb();
|
||||
};
|
||||
|
|
5
ep.json
5
ep.json
|
@ -6,10 +6,11 @@
|
|||
"padUpdate": "ep_email_notifications/update",
|
||||
"handleMessage": "ep_email_notifications/update",
|
||||
"eejsBlock_scripts": "ep_email_notifications/client",
|
||||
"eejsBlock_editbarMenuRight": "ep_email_notifications/client:eejsBlock_toolbarRight"
|
||||
"eejsBlock_editbarMenuRight": "ep_email_notifications/client:eejsBlock_toolbarRight",
|
||||
"eejsBlock_embedPopup": "ep_email_notifications/client:eejsBlock_embedPopup"
|
||||
},
|
||||
"client_hooks": {
|
||||
"postAceInit":"ep_email_notifications/static/js/ep_email",
|
||||
"documentReady":"ep_email_notifications/static/js/ep_email",
|
||||
"handleClientMessage_emailSubscriptionSuccess":"ep_email_notifications/static/js/ep_email"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
"contributors": [],
|
||||
"dependencies": {
|
||||
"emailjs": ">= 0.2.7",
|
||||
"buffertools": ">= 1.0.8"
|
||||
"buffertools": ">= 1.0.8",
|
||||
"validator": ">= 0.4.21"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.1"
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
exports.documentReady = function(){
|
||||
// after 10 seconds if we dont already have an email for this author then prompt them
|
||||
setTimeout(function(){init()},10000);
|
||||
|
||||
// subscribe by email can be active..
|
||||
$('.ep_email_form').submit(function(){
|
||||
sendEmailToServer();
|
||||
return false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
exports.handleClientMessage_emailSubscriptionSuccess = function(hook, context){ // was subscribing to the email a big win or fail?
|
||||
if(context.payload == false){
|
||||
showAlreadyRegistered();
|
||||
|
@ -6,16 +18,14 @@ exports.handleClientMessage_emailSubscriptionSuccess = function(hook, context){
|
|||
}
|
||||
}
|
||||
|
||||
exports.postAceInit = function(){
|
||||
// after 10 seconds if we dont already have an email for this author then prompt them
|
||||
setTimeout(function(){init()},10000);
|
||||
}
|
||||
|
||||
function init(){
|
||||
if(clientHasAlreadyRegistered){ // if the client has already registered for emails on this pad.
|
||||
showAlreadyRegistered(); // client has already registered, let em know..
|
||||
}else{
|
||||
askClientToEnterEmail(); // ask the client to register
|
||||
var popUpIsAlreadyVisible = $('#ep_email').is(":visible");
|
||||
if(!popUpIsAlreadyVisible){ // if the popup isn't already visible
|
||||
if(clientHasAlreadyRegistered()){ // if the client has already registered for emails on this pad.
|
||||
// showAlreadyRegistered(); // client has already registered, let em know..
|
||||
}else{
|
||||
askClientToEnterEmail(); // ask the client to register
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,16 +65,16 @@ function clientHasAlreadyRegistered(){ // Has the client already registered for
|
|||
function askClientToEnterEmail(){
|
||||
$.gritter.add({
|
||||
// (string | mandatory) the heading of the notification
|
||||
title: "Email notifications for this pad",
|
||||
title: "Enter your email to recieve an email when someone modifies this pad",
|
||||
// (string | mandatory) the text inside the notification
|
||||
text: "<form id='ep_email_form'><label for='ep_email'><input id='ep_email' placeholder='your@email.com' value='foo@bar.com' type=email><input type=submit></form>",
|
||||
text: "<form class='ep_email_form'><label for='ep_email'><input id='ep_email' placeholder='your@email.com' style='padding:5px;width:200px;' type=email><input type=submit style='padding:5px;'></form>",
|
||||
// (bool | optional) if you want it to fade out on its own or just sit there
|
||||
sticky: true,
|
||||
// (int | optional) the time you want it to be alive for before fading out
|
||||
time: '2000',
|
||||
// the function to bind to the form
|
||||
after_open: function(e){
|
||||
$('#ep_email_form').submit(function(){
|
||||
$('.ep_email_form').submit(function(){
|
||||
$(e).hide();
|
||||
sendEmailToServer();
|
||||
return false;
|
||||
|
|
3
templates/embedFrame.html
Normal file
3
templates/embedFrame.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<br>
|
||||
<h2>Recieve email notifications on change</h2>
|
||||
<form class='ep_email_form'><label for='ep_email'><input id='ep_email' placeholder='your@email.com' style="padding:5px;margin-top:10px;width:300px;" type=email><input style="padding:5px;" type=submit></form>
|
16
update.js
16
update.js
|
@ -1,6 +1,7 @@
|
|||
var db = require('../../src/node/db/DB').db,
|
||||
API = require('../../src/node/db/API.js'),
|
||||
async = require('../../src/node_modules/async'),
|
||||
check = require('validator').check,
|
||||
settings = require('../../src/node/utils/Settings');
|
||||
|
||||
var pluginSettings = settings.ep_email_notifications;
|
||||
|
@ -44,7 +45,18 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
}); // end async for each
|
||||
}
|
||||
|
||||
if(alreadyExists == false){
|
||||
var validatesAsEmail = check(context.message.data.userInfo.email).isEmail();
|
||||
if(!validatesAsEmail){ // send validation failed if it's malformed.. y'know in general fuck em!
|
||||
console.warn("Dropped email subscription due to malformed email address");
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
data:{
|
||||
type: "emailSubscriptionSuccess",
|
||||
payload: false
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(alreadyExists == false && validatesAsEmail == true){
|
||||
|
||||
console.warn ("Wrote to the database and sent client a positive response ",context.message.data.userInfo.email);
|
||||
|
||||
|
@ -61,7 +73,7 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
data:{
|
||||
type: "email_subscription_success",
|
||||
type: "emailSubscriptionSuccess",
|
||||
payload: true
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue