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