) {
+ switch (m) {
+ case "tpl":
+ setTemplate(args[0]);
+ case "logged":
+ if (user == null)
+ throw sugoi.ControllerAction.RedirectAction("/?__redirect=" + Web.getURI());
+ case "admin":
+ if (user == null || !user.isAdmin())
+ throw sugoi.ControllerAction.RedirectAction("/");
+ default:
}
}
@@ -124,111 +135,109 @@ class BaseApp {
*/
function detectLang() {
var l = Web.getClientHeader("Accept-Language");
- if( l != null )
- for( l in l.split(",") ) {
+ if (l != null)
+ for (l in l.split(",")) {
l = l.split(";")[0];
l = l.split("-")[0];
l = StringTools.trim(l);
- for( a in App.config.LANGS )
- if( a == l )
+ for (a in App.config.LANGS)
+ if (a == l)
return a;
}
-
+
return App.config.LANG;
}
-
-
+
/**
* Setup current app language
*/
function setupLang() {
-
- //this app is monolingual and doesn't manage i18n
- if (App.config.LANG == "master") return;
-
- //lang is taken from user object or from HTTP headers
- if ( session.lang == null || !Lambda.has(App.config.LANGS, session.lang) ){
+ // this app is monolingual and doesn't manage i18n
+ if (App.config.LANG == "master")
+ return;
+
+ // lang is taken from user object or from HTTP headers
+ if (session.lang == null || !Lambda.has(App.config.LANGS, session.lang)) {
session.lang = (user == null) ? detectLang() : user.lang;
}
-
- //override if param is given
+
+ // override if param is given
var lang = params.get("lang");
- if ( lang != null && Lambda.has(App.config.LANGS, lang) ){
+ if (lang != null && Lambda.has(App.config.LANGS, lang)) {
session.lang = lang;
-
}
-
- //init lang
+
+ // init lang
initLang(session.lang);
}
-
+
/**
* Get current application langage (2 letters lowercase)
*/
- public function getLang(){
+ public function getLang() {
return (session != null && session.lang != null && session.lang != "") ? session.lang : App.config.LANG;
}
public function rollback() {
- if( cnx != null ) cnx.rollback();
+ if (cnx != null)
+ cnx.rollback();
sys.db.Manager.cleanup();
- if( user != null && session != null )
+ if (user != null && session != null)
user = session.user;
// does not reset session
}
- public function setCookie( oldCookie : String ){
- if( session != null && session.sid != null && session.sid != oldCookie ) {
- Web.setHeader("Set-Cookie", cookieName+"=" + session.sid + "; path=/;");
+ public function setCookie(oldCookie:String) {
+ if (session != null && session.sid != null && session.sid != oldCookie) {
+ Web.setHeader("Set-Cookie", cookieName + "=" + session.sid + "; path=/;");
}
}
function mainLoop() {
params = Web.getParams();
-
- //Get session
+
+ // Get session
var sids = [];
var cookieSid = Web.getCookies().get(cookieName);
- if( params.exists("sid") ) sids.push(params.get("sid"));
- if( cookieSid != null ) sids.push(cookieSid);
+ if (params.exists("sid"))
+ sids.push(params.get("sid"));
+ if (cookieSid != null)
+ sids.push(cookieSid);
session = sugoi.db.Session.init(sids);
-
- //Check for maintenance
+
+ // Check for maintenance
maintain = sugoi.db.Variable.getInt("maintain") != 0;
user = session.user;
-
- //setup langage
+
+ // setup langage
setupLang();
-
-
- if( maintain && ((user != null && user.isAdmin()) ) )
+
+ if (maintain && ((user != null && user.isAdmin())))
maintain = false;
-
+
setCookie(cookieSid);
-
- if( maintain ) {
+
+ if (maintain) {
setTemplate("maintain.mtt");
executeTemplate();
return;
}
-
- //dispatching
+
+ // dispatching
try {
-
uri = Web.getURI();
- if ( StringTools.endsWith(uri, "/index.n") ) uri = uri.substr(0, -8);
-
- //"before dispatch" callback
+ if (StringTools.endsWith(uri, "/index.n"))
+ uri = uri.substr(0, -8);
+
+ // "before dispatch" callback
beforeDispatch();
-
+
var d = new haxe.web.Dispatch(uri, params);
d.onMeta = onMeta;
d.dispatch(new controller.Main());
-
- } catch ( e : haxe.web.Dispatch.DispatchError ) {
-
- //dispatch / routing error
- if ( App.config.DEBUG ) {
+ } catch (e:haxe.web.Dispatch.DispatchError) {
+ // dispatch / routing error
+ if (App.config.DEBUG) {
#if neko
neko.Lib.rethrow(e);
#else
@@ -238,48 +247,48 @@ class BaseApp {
cnx.rollback();
Web.redirect("/");
return;
-
- } catch ( e : sugoi.ControllerAction) {
-
- switch( e ) {
- case RedirectAction(url):
- Web.redirect(url);
- template = null;
- case ErrorAction(url, text), OkAction(url,text):
- if( text == null ) {
- text = url;
- url = Web.getURI();
- }
- Web.redirect(url);
- var error = switch(e) { case ErrorAction(_): true; default: false; };
- if( error ) rollback();
- if ( error ) {
- session.addMessage(text,true);
- }else {
- session.addMessage(text);
- }
- template = null;
+ } catch (e:sugoi.ControllerAction) {
+ switch (e) {
+ case RedirectAction(url):
+ Web.redirect(url);
+ template = null;
+ case ErrorAction(url, text), OkAction(url, text):
+ if (text == null) {
+ text = url;
+ url = Web.getURI();
+ }
+ Web.redirect(url);
+ var error = switch (e) {
+ case ErrorAction(_): true;
+ default: false;
+ };
+ if (error)
+ rollback();
+ if (error) {
+ session.addMessage(text, true);
+ } else {
+ session.addMessage(text);
+ }
+ template = null;
}
}
-
- //Render template
- if ( template == null ) {
+
+ // Render template
+ if (template == null) {
saveAndClose();
- } else {
+ } else {
executeTemplate(true); // will saveAndClose
}
}
-
+
/**
* Override this function if you want
* to insert some actions
*/
- public function beforeDispatch() {
-
- }
+ public function beforeDispatch() {}
- public function logError( e : Dynamic, ?stack : String ) {
- var stack = if( stack != null ) stack else haxe.CallStack.toString(haxe.CallStack.exceptionStack());
+ public function logError(e:Dynamic, ?stack:String) {
+ var stack = if (stack != null) stack else haxe.CallStack.toString(haxe.CallStack.exceptionStack());
var message = new StringBuf();
message.add(Std.string(e));
message.add("\n");
@@ -288,43 +297,42 @@ class BaseApp {
var e = new sugoi.db.Error();
e.url = Web.getURI();
e.ip = Web.getClientIP();
- e.user = if( user != null ) user else null;
+ e.user = if (user != null) user else null;
e.date = Date.now();
e.userAgent = Web.getClientHeader("User-Agent");
e.error = message.toString();
e.insert();
}
- function errorHandler( e:Dynamic ) {
+ function errorHandler(e:Dynamic) {
try {
var stack = haxe.CallStack.toString(haxe.CallStack.exceptionStack());
// ROLLBACK and LOG
- if ( cnx != null ) {
+ if (cnx != null) {
cnx.rollback();
- logError(e,stack);
+ logError(e, stack);
}
-
- //log also in a file, in case we don't have a valid connexion to DB
- Web.logMessage(e+"\n" + stack);
-
+
+ // log also in a file, in case we don't have a valid connexion to DB
+ Web.logMessage(e + "\n" + stack);
+
maintain = true;
view = new View();
view.message = Std.string(e);
- if ( App.config.DEBUG || (user != null && user.isAdmin()) ) {
+ if (App.config.DEBUG || (user != null && user.isAdmin())) {
view.stack = stack;
}
-
+
setTemplate("error.mtt");
executeTemplate(false);
-
- } catch( e : Dynamic ) {
+ } catch (e:Dynamic) {
Sys.print("");
- Sys.println("Error : "+try Std.string(e) catch( e : Dynamic ) "???");
+ Sys.println("Error : " + try Std.string(e) catch (e:Dynamic) "???");
Sys.println(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
try {
- if( cnx != null )
- sugoi.db.Error.manager.get(0,false);
- } catch( e : Dynamic ) {
+ if (cnx != null)
+ sugoi.db.Error.manager.get(0, false);
+ } catch (e:Dynamic) {
Sys.println("Initializing Database...");
sys.db.Admin.initializeDatabase();
Sys.println("Done");
@@ -339,7 +347,7 @@ class BaseApp {
*/
function init() {
maintain = App.config.getBool("maintain");
- if( maintain ) {
+ if (maintain) {
view = new View();
setTemplate("maintain.mtt");
executeTemplate(false);
@@ -348,23 +356,23 @@ class BaseApp {
try {
var dbstr = App.config.get("database");
var dbreg = ~/([^:]+):\/\/([^:]+):([^@]*?)@([^:]+)(:[0-9]+)?\/(.*?)$/;
- if( !dbreg.match(dbstr) )
+ if (!dbreg.match(dbstr))
throw "Configuration requires a valid database attribute, format is : mysql://user:password@host:port/dbname";
var port = dbreg.matched(5);
var dbparams = {
- user:dbreg.matched(2),
- pass:dbreg.matched(3),
- host:dbreg.matched(4),
- port:port == null ? 3306 : Std.parseInt(port.substr(1)),
- database:dbreg.matched(6),
- socket:null
+ user: dbreg.matched(2),
+ pass: dbreg.matched(3),
+ host: dbreg.matched(4),
+ port: port == null ? 3306 : Std.parseInt(port.substr(1)),
+ database: dbreg.matched(6),
+ socket: null
};
cnx = sys.db.Mysql.connect(dbparams);
- } catch( e : Dynamic ) {
+ } catch (e:Dynamic) {
errorHandler(e);
return false;
}
- if( App.config.SQL_LOG )
+ if (App.config.SQL_LOG)
cnx = new sugoi.tools.DebugConnection(cnx);
return true;
}
@@ -372,7 +380,7 @@ class BaseApp {
function cloneApp() {
// ensure that we have no variable initialized in app loop
var app = new App();
- var bapp : BaseApp = app;
+ var bapp:BaseApp = app;
bapp.cnx = cnx;
bapp.view = new View();
App.current = app;
@@ -380,13 +388,15 @@ class BaseApp {
}
function run() {
-
// Will close the connection
- sys.db.Transaction.main(cnx, cloneApp, function(e) { var b : BaseApp = App.current; b.errorHandler(e); });
+ sys.db.Transaction.main(cnx, cloneApp, function(e) {
+ var b:BaseApp = App.current;
+ b.errorHandler(e);
+ });
App.current = null;
}
- function sendHeaders(){
+ function sendHeaders() {
Web.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
Web.setHeader("Pragma", "no-cache");
Web.setHeader("Expires", "-1");
@@ -396,28 +406,28 @@ class BaseApp {
}
static function main() {
-
/**
* this macro will parse the code and generate the allTexts.pot file
* which will be used as a template for translation files (*.po and *.mo)
*/
#if i18n_parsing
- if( false ) sugoi.i18n.GetText.parse(["src", "lang/master","js","common"], "www/lang/allTexts.pot");
+ if (false)
+ sugoi.i18n.GetText.parse(["src", "lang/master", "js", "common"], "www/lang/allTexts.pot");
#end
-
+
App.current = new App();
- var a : BaseApp = App.current;
-
+ var a:BaseApp = App.current;
+
a.sendHeaders();
- if( !a.init() ) {
+ if (!a.init()) {
a = null;
return;
}
a.run();
a = null;
#if neko
- if ( App.config.getInt("cache", 0) == 1 ) {
+ if (App.config.getInt("cache", 0) == 1) {
neko.Web.cacheModule(App.main);
}
#end
diff --git a/src/sugoi/mail/Mail.hx b/src/sugoi/mail/Mail.hx
index 862fbb9..1d9787f 100644
--- a/src/sugoi/mail/Mail.hx
+++ b/src/sugoi/mail/Mail.hx
@@ -32,8 +32,8 @@ class Mail implements IMail {
public function setSender(email, ?name, ?userId) {
if (!isValid(email))
throw "invalid sender email : \"" + email + "\"";
-
- sender = {name: name, email: email, userId: userId};
+ var finalName = (name != null) ? thx.text.Diactrics.clean(name) : null;
+ sender = {name: finalName, email: email, userId: userId};
return this;
}
diff --git a/www/lang/texts_fr.po b/www/lang/texts_fr.po
index 6f14500..80bf3c3 100644
--- a/www/lang/texts_fr.po
+++ b/www/lang/texts_fr.po
@@ -1538,7 +1538,7 @@ msgid ""
"Group and user 'admin' created. Your email is 'admin@cagette.net' and your "
"password is 'admin'"
msgstr ""
-"Groupe et utilisateur 'admin' créé. Votre email est 'admin@cagette.net' et "
+"Groupe et utilisateur 'admin' créé. Votre email est 'admin@cagettepei.re' et "
"votre mot de passe est 'admin'"
#: src/controller/Install.hx:4677
@@ -4551,7 +4551,7 @@ msgstr "Extrait non exhaustif des produits proposés :"
#: lang/master/tpl/group/view.mtt:5027
msgid "http://www.cagette.net"
-msgstr "http://www.cagette.net"
+msgstr "https://git.artcode.re/cagetters/cagettepei"
#: lang/master/tpl/group/view.mtt:5060
msgid "Cagette.net, the free software of food direct-selling"
@@ -4618,7 +4618,7 @@ msgid ""
"Cagette.net is made by
"
msgstr ""
-"CagettePéi est une fourche du logiciel Cagette.net réalisé par
"
#: lang/master/tpl/validate/user.mtt:2124