Add good redirection after login
This commit is contained in:
parent
c363e309c1
commit
226e9cbbde
|
|
@ -15,9 +15,15 @@ func (c *LoginController) Prepare() {
|
|||
}
|
||||
|
||||
func (c *LoginController) Get() {
|
||||
routeRedirect := c.Ctx.Input.Param(":route")
|
||||
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess != nil {
|
||||
if routeRedirect == "" {
|
||||
c.Redirect(variables.UserRoute, 302)
|
||||
} else {
|
||||
c.Redirect("/"+routeRedirect, 302)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -25,9 +31,15 @@ func (c *LoginController) Get() {
|
|||
}
|
||||
|
||||
func (c *LoginController) Post() {
|
||||
routeRedirect := c.Ctx.Input.Param(":route")
|
||||
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess != nil {
|
||||
if routeRedirect == "" {
|
||||
c.Redirect(variables.RootRoute, 302)
|
||||
} else {
|
||||
c.Redirect("/"+routeRedirect, 302)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +51,11 @@ func (c *LoginController) Post() {
|
|||
}
|
||||
|
||||
c.SetSession(variables.SessionName, login)
|
||||
if routeRedirect == "" {
|
||||
c.Redirect(variables.UserRoute, 302)
|
||||
} else {
|
||||
c.Redirect("/"+routeRedirect, 302)
|
||||
}
|
||||
}
|
||||
|
||||
func isLoginOK(lgn, pwd string) bool {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type ViewRelayController struct {
|
|||
func (c *ViewRelayController) Prepare() {
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess == nil {
|
||||
c.Redirect(variables.LoginRoute, 302)
|
||||
c.Redirect(variables.LoginRouteNoRegex+variables.ViewRelaysRoute, 302)
|
||||
} else {
|
||||
c.Data["IsAuthentificated"] = true
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ type CommandRelayController struct {
|
|||
func (c *CommandRelayController) Prepare() {
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess == nil {
|
||||
c.Redirect(variables.LoginRoute, 302)
|
||||
c.Redirect(variables.LoginRouteNoRegex+variables.CommandRelayRoute, 302)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ type SensorsController struct {
|
|||
func (c *SensorsController) Prepare() {
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess == nil {
|
||||
c.Redirect(variables.LoginRoute, 302)
|
||||
c.Redirect(variables.LoginRouteNoRegex+variables.SensorsRoute, 302)
|
||||
} else {
|
||||
c.Data["IsAuthentificated"] = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ type UserController struct {
|
|||
func (c *UserController) Prepare() {
|
||||
sess := c.GetSession(variables.SessionName)
|
||||
if sess == nil {
|
||||
c.Redirect(variables.LoginRoute, 302)
|
||||
c.Redirect(variables.LoginRouteNoRegex+variables.UserRoute, 302)
|
||||
} else {
|
||||
c.Data["IsAuthentificated"] = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ var (
|
|||
CommandRelayRoute = "/command/relay/" + sensorMacRegex
|
||||
|
||||
SensorsRoute = "/sensors"
|
||||
LoginRoute = "/login"
|
||||
LoginRoute = "/login/:route(.*)"
|
||||
LoginRouteNoRegex = "/login"
|
||||
UserRoute = "/user"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="/static/js/jquery.sha256.min.js"></script>
|
||||
<script type="application/javascript">
|
||||
$("form").attr('action', window.location.pathname);
|
||||
$("#loginForm").submit(function() {
|
||||
$('#inputPassword').val($.sha256($('#inputPassword').val()));
|
||||
console.log("Password: "+$('#inputPassword').val());
|
||||
|
|
|
|||
Loading…
Reference in New Issue