parent
d3b1b17aac
commit
f67d5c50e9
8 changed files with 42 additions and 114 deletions
@ -1,9 +0,0 @@ |
|||||||
<!-- Copyright © 2023 Entreprise SkamKraft --> |
|
||||||
|
|
||||||
<div class="my-modal"> |
|
||||||
<p class="modal-title">Login success</p> |
|
||||||
<div> |
|
||||||
<button id="ok" class="btn btn-val">Continue</button> |
|
||||||
<button id="forget_login" class="btn btn-cancel">Forget agent</button> |
|
||||||
</div> |
|
||||||
</div> |
|
@ -1,10 +0,0 @@ |
|||||||
<!-- Copyright © 2023 Entreprise SkamKraft --> |
|
||||||
|
|
||||||
<div class="my-modal"> |
|
||||||
<p class="modal-title">Login success</p> |
|
||||||
<p class="show-token"></p> |
|
||||||
<div> |
|
||||||
<button id="ok" class="btn btn-val">Continue</button> |
|
||||||
<button id="forget_reg" class="btn btn-cancel">Forget agent</button> |
|
||||||
</div> |
|
||||||
</div> |
|
@ -1,51 +1,39 @@ |
|||||||
import { Modal } from "../skama_code/ui/modal.js"; |
|
||||||
import { Auth } from "../skama_code/auth/auth.js"; |
import { Auth } from "../skama_code/auth/auth.js"; |
||||||
import { My } from "../skama_code/api/agent.js"; |
import { My } from "../skama_code/api/agent.js"; |
||||||
import home from "./home.js"; |
import home from "./home.js"; |
||||||
import menu_mod from "./menu_mod.js"; |
import menu_mod from "./menu_mod.js"; |
||||||
|
|
||||||
export default function login(temp_engine) { |
export default function login(temp_engine) { |
||||||
let auth = new Auth(true); |
const auth = new Auth(); |
||||||
let modal = new Modal("login-modal", temp_engine); |
|
||||||
|
|
||||||
modal.add_class("ext-modal"); |
|
||||||
temp_engine.after_render((temp_engine) => { |
temp_engine.after_render((temp_engine) => { |
||||||
modal.load("templates/auth/login_modal.html") |
|
||||||
menu_mod(temp_engine); |
menu_mod(temp_engine); |
||||||
temp_engine.add_event("#ok", "click", () => { |
|
||||||
home(temp_engine); |
|
||||||
}); |
|
||||||
|
|
||||||
temp_engine.add_event("#forget_login", "click", () => { |
|
||||||
My.agent = null; |
|
||||||
auth.unload_token(); |
|
||||||
modal.close(); |
|
||||||
render_login(); |
|
||||||
}); |
|
||||||
|
|
||||||
temp_engine.add_event("#val", "click", () => { |
temp_engine.add_event("#val", "click", () => { |
||||||
let token = $("#in-token").val(); |
const is_checked = $("#box-remember").is(":checked"); |
||||||
auth.login(token); |
const token = $("#in-token").val(); |
||||||
|
auth.store = is_checked; |
||||||
|
auth.login(token) |
||||||
}); |
}); |
||||||
|
|
||||||
temp_engine.add_event("#cancel", "click", () => { |
temp_engine.add_event("#cancel", "click", () => { |
||||||
$("#in-token").val(""); |
$("#in-token").val(""); |
||||||
|
$("#box-remember").prop("checked", false); |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
|
||||||
temp_engine.render(`templates/auth/login.html`); |
|
||||||
|
|
||||||
auth.done((agent) => { |
auth.done((agent) => { |
||||||
modal.show(); |
|
||||||
My.agent = agent; |
My.agent = agent; |
||||||
}).fail((errs) => { |
if(auth.store) localStorage.setItem("token", agent.token) |
||||||
|
home(temp_engine); |
||||||
|
}) |
||||||
|
|
||||||
|
auth.fail((errors) => { |
||||||
$(".errors").html(""); |
$(".errors").html(""); |
||||||
errs.forEach(err => { |
errors.forEach(error => { |
||||||
$(".errors").append(` |
$(".errors").append(`<p>${error}</p>`); |
||||||
<p>${err}</p> |
|
||||||
`);
|
|
||||||
}); |
|
||||||
}); |
}); |
||||||
|
}) |
||||||
|
|
||||||
auth.relog(); |
temp_engine.render(`templates/auth/login.html`); |
||||||
} |
} |
@ -1,61 +1,15 @@ |
|||||||
import { Modal } from "../skama_code/ui/modal.js"; |
|
||||||
import { Auth } from "../skama_code/auth/auth.js"; |
import { Auth } from "../skama_code/auth/auth.js"; |
||||||
import { My } from "../skama_code/api/agent.js"; |
import { My } from "../skama_code/api/agent.js"; |
||||||
|
import { Faction } from "../skama_code/api/faction.js" |
||||||
import home from "./home.js"; |
import home from "./home.js"; |
||||||
import menu_mod from "./menu_mod.js"; |
import menu_mod from "./menu_mod.js"; |
||||||
|
|
||||||
export default function reg(temp_engine) { |
export default function reg(temp_engine) { |
||||||
let active = false; |
|
||||||
let auth = new Auth(true); |
let auth = new Auth(true); |
||||||
let modal = new Modal("reg-modal", temp_engine); |
|
||||||
|
|
||||||
modal.add_class("ext-modal"); |
|
||||||
temp_engine.after_render((temp_engine) => { |
temp_engine.after_render((temp_engine) => { |
||||||
menu_mod(temp_engine); |
menu_mod(temp_engine); |
||||||
modal.load("templates/auth/reg_modal.html"); |
|
||||||
temp_engine.add_event("#ok", "click", () => { |
|
||||||
home(temp_engine); |
|
||||||
}); |
|
||||||
|
|
||||||
temp_engine.add_event("#forget_reg", "click", () => { |
|
||||||
My.agent = null; |
|
||||||
auth.unload_token(); |
|
||||||
modal.close(); |
|
||||||
render_reg(); |
|
||||||
}); |
|
||||||
|
|
||||||
temp_engine.add_event("#val", "click", () => { |
|
||||||
if (!active) { |
|
||||||
active = true; |
|
||||||
let name = $("#in-name").val(); |
|
||||||
let faction = $("#in-faction").val(); |
|
||||||
auth.register({ |
|
||||||
name: name, |
|
||||||
faction: faction |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
temp_engine.add_event("#cancel", "click", () => { |
|
||||||
$("#in-name").val(""); |
|
||||||
$("#in-faction").val(""); |
|
||||||
}); |
|
||||||
}); |
}); |
||||||
|
|
||||||
temp_engine.render(`templates/auth/reg.html`); |
temp_engine.render(`templates/auth/reg.html`); |
||||||
|
|
||||||
auth.done((agent) => { |
|
||||||
$(".show-token").text(agent.token); |
|
||||||
modal.show(); |
|
||||||
My.agent = agent; |
|
||||||
active = false; |
|
||||||
}).fail((errs) => { |
|
||||||
$(".errors").html(""); |
|
||||||
errs.forEach(err => { |
|
||||||
$(".errors").append(` |
|
||||||
<p>${err}</p> |
|
||||||
`);
|
|
||||||
}); |
|
||||||
active = false; |
|
||||||
}); |
|
||||||
} |
} |
@ -1 +1 @@ |
|||||||
Subproject commit 7bbbfc565e3e2555d50c4e117311d98e629998c9 |
Subproject commit 7f516288452f67f345be6b2eb8f4eb1137a7dd43 |
Loading…
Reference in New Issue