mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-12-27 09:58:20 +01:00
commit
05ee884e8d
119
grs/main.js
119
grs/main.js
@ -1,119 +0,0 @@
|
||||
var scheme = undefined;
|
||||
String.prototype.__ = function()
|
||||
{
|
||||
return this
|
||||
}
|
||||
function subscribe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
// get scheme
|
||||
$.get(prefix+"/subscribe.html")
|
||||
.done(function(d) {
|
||||
scheme = $.parseHTML(d)
|
||||
var obs = riot.observable()
|
||||
$(scheme).css("visibility","hidden")
|
||||
$("#desktop" ).append(scheme)
|
||||
obs.on("exit", function(){
|
||||
$(scheme).remove()
|
||||
scheme = undefined
|
||||
})
|
||||
obs.on("rendered", function(d){
|
||||
$(".afx-window-title", scheme).html("Subscribe")
|
||||
$("[data-id='send']", scheme).click(function(){
|
||||
var status = $("[data-id='status']", scheme)
|
||||
status.html("");
|
||||
var els = $("[data-class='data']", scheme)
|
||||
var data = {}
|
||||
|
||||
for(var i = 0; i < els.length; i++)
|
||||
data[els[i].name] = $(els[i]).val()
|
||||
if(data.email == "" || data.subject == "" || data.content == "" || data.name == "")
|
||||
return status.html("Please enter all the fields");
|
||||
var re = /^(([^<>()\[\]\\.,;:\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(!re.test(String(data.email).toLowerCase()))
|
||||
return status.html("Email is not correct");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: prefix + "/subscribe.lua",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
dataType: 'json',
|
||||
success: null
|
||||
}).done(function(r){
|
||||
if(r.error)
|
||||
alert(r.error)
|
||||
else
|
||||
{
|
||||
obs.trigger("exit")
|
||||
alert("You have been subscribed. Thanks")
|
||||
}
|
||||
}).fail(function(e, s){
|
||||
alert("Error: " + e)
|
||||
})
|
||||
})
|
||||
$(scheme).css("visibility","visible")
|
||||
})
|
||||
riot.mount(scheme, {observable:obs})
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "Cannot get the form" );
|
||||
})
|
||||
}
|
||||
function mailtoMe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
// get scheme
|
||||
$.get(prefix+"/sendto.html")
|
||||
.done(function(d) {
|
||||
scheme = $.parseHTML(d)
|
||||
var obs = riot.observable()
|
||||
$(scheme).css("visibility","hidden")
|
||||
$("#desktop" ).append(scheme)
|
||||
obs.on("exit", function(){
|
||||
$(scheme).remove()
|
||||
scheme = undefined
|
||||
})
|
||||
obs.on("rendered", function(d){
|
||||
$(".afx-window-title", scheme).html("Send me an email")
|
||||
$("[data-id='send']", scheme).click(function(){
|
||||
var status = $("[data-id='status']", scheme)
|
||||
status.html("");
|
||||
var els = $("[data-class='data']", scheme)
|
||||
var data = {}
|
||||
|
||||
for(var i = 0; i < els.length; i++)
|
||||
data[els[i].name] = $(els[i]).val()
|
||||
if(data.email == "" || data.subject == "" || data.content == "" || data.name == "")
|
||||
return status.html("Please enter all the fields");
|
||||
var re = /^(([^<>()\[\]\\.,;:\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(!re.test(String(data.email).toLowerCase()))
|
||||
return status.html("Email is not correct");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: prefix + "/sendmail.lua",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
dataType: 'json',
|
||||
success: null
|
||||
}).done(function(r){
|
||||
if(r.error)
|
||||
alert(r.error)
|
||||
else
|
||||
{
|
||||
obs.trigger("exit")
|
||||
alert("Email sent. Thank")
|
||||
}
|
||||
}).fail(function(){
|
||||
alert("Service unavailable at the moment")
|
||||
})
|
||||
})
|
||||
$(scheme).css("visibility","visible")
|
||||
})
|
||||
riot.mount(scheme, {observable:obs})
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "Cannot get the form" );
|
||||
})
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
|
||||
if not REQUEST.json then
|
||||
fail("unknown request")
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.json))
|
||||
local to = "xsang.le@gmail.com"
|
||||
local from = "From: "..rq.email.."\n"
|
||||
local suject = "Subject: "..rq.subject.."\n"
|
||||
local content = "Contact request from:"..rq.name.."\n Email: "..rq.email.."\n"..rq.content.."\n"
|
||||
|
||||
local cmd = 'echo "'..utils.escape(from..suject..content)..'"| sendmail '..to
|
||||
|
||||
--print(cmd)
|
||||
local r = os.execute(cmd)
|
||||
|
||||
if r then
|
||||
result(r)
|
||||
else
|
||||
fail("Cannot send email at the moment, the service may be down")
|
||||
end
|
@ -1,22 +0,0 @@
|
||||
|
||||
if not REQUEST.json then
|
||||
fail("unknown request")
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.json))
|
||||
local sample = {name = "toto", email = "toto@mail.fr"}
|
||||
local db = require("db.model").get("mrsang","subscribers",sample)
|
||||
|
||||
if db then
|
||||
-- check if email is exist
|
||||
local data = db:find({exp = { ["="] = { email = rq.email } }})
|
||||
if data and #data > 0 then
|
||||
fail("You are already/previously subscribed")
|
||||
else
|
||||
-- save to database
|
||||
db:insert(rq)
|
||||
result("Ok")
|
||||
end
|
||||
db:close()
|
||||
else
|
||||
fail("Cannot subscribe at the moment, the service may be down")
|
||||
end
|
7
index.ls
7
index.ls
@ -25,10 +25,6 @@
|
||||
<link rel="stylesheet" type="text/css" href="grs/ubuntu-regular.css" />
|
||||
<link rel="stylesheet" type="text/css" href="grs/font-awesome.css" />
|
||||
<link rel="stylesheet" type="text/css" href="grs/mainsite.css" />
|
||||
<script src="grs/gscripts/jquery-3.2.1.min.js"> </script>
|
||||
<script src="grs/gscripts/riot.min.js"> </script>
|
||||
<script src="grs/resources/antos_tags.js"></script>
|
||||
<script src="grs/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id = "desktop">
|
||||
@ -36,8 +32,7 @@
|
||||
<ul>
|
||||
<li ><i class = "fa fa-address-card"></i><a href="https://info.lxsang.me" >Porfolio</a></li>
|
||||
<li><i class = "fa fa-newspaper-o"></i><a href="https://blog.lxsang.me" >Blog</a></li>
|
||||
<li><i class = "fa fa-paper-plane"></i><a href="#" onclick="mailtoMe('grs')" >Contact</a></li>
|
||||
<li > <i class = "fa fa-globe"></i><a href = "https://os.lxsang.me" target="_blank">Web OS</a></li>
|
||||
<li > <i class = "fa fa-globe"></i><a href = "https://os.iohub.dev" target="_blank">Web OS</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div id = "center">
|
||||
|
Loading…
Reference in New Issue
Block a user