commit 864abbc1463d354334ab7c48a076e44d413deb6e
parent 4fc922750b673a41356869836067a6e82fcbb70c
Author: Peter Kosyh <p.kosyh@gmail.com>
Date: Fri, 4 Sep 2020 17:48:47 +0300
logout & profile
Diffstat:
6 files changed, 78 insertions(+), 10 deletions(-)
diff --git a/ii-node/lib/style.css b/ii-node/lib/style.css
@@ -35,7 +35,7 @@
text-decoration: none;
}
-#echolist, #topiclist {
+#echolist, #topiclist, #profile, #login {
margin: 0;
margin-left:auto;
margin-right:auto;
@@ -81,11 +81,11 @@
padding: 0;
margin: 0;
}
-#echolist .even,#topiclist .even {
+#echolist .even {
background: #ffffea;
}
-#echolist .odd,#topiclist .odd {
+.odd {
background: #eaffff;
}
@@ -151,10 +151,21 @@
text-align: right;
}
-#header .links a, #header .links a:visited {
+.links a, .links a:visited {
color: #ea5555;
}
-
+#footer {
+ text-align: right;
+ font-size: smaller;
+ font-style: italic;
+ margin-top: 1em;
+}
+#profile td, #login td{
+ padding: 0.5em;
+}
+#profile .links, #login .links {
+ text-align: center;
+}
@media (max-width: 640px) {
.extra {
display: none;
diff --git a/ii-node/tpl/footer.tpl b/ii-node/tpl/footer.tpl
@@ -1,3 +1,7 @@
+<div id="footer">
+Powered by ii-go / 2020
+</div>
+
</div>
</body>
</html>
diff --git a/ii-node/tpl/header.tpl b/ii-node/tpl/header.tpl
@@ -19,8 +19,10 @@
</td>
<td class="links">
<span>
- {{ with .User }}
- {{.Name}}
+ {{ if .User.Name }}
+ <a href="/profile">{{.User.Name}}</a>
+ {{else}}
+ <a href="/login">Login</a>
{{end}}
{{ with .Echo }}
:: <a href="/{{.}}/new">New topic</a>
diff --git a/ii-node/tpl/login.tpl b/ii-node/tpl/login.tpl
@@ -1,7 +1,21 @@
{{template "header.tpl"}}
+
<form method="post" enctype="application/x-www-form-urlencoded" action="/login">
-<input type="text" name="username" class="login" placeholder="username"><br>
-<input type="password" name="password" class="passwd" placeholder="password"><br>
-<button class="form-button">Login</button>
+<table id="login" cellspacing=0 cellpadding=0>
+
+<tr class="odd"><td>
+<input type="text" name="username" class="login" placeholder="username">
+</td></tr>
+
+<tr class="even"><td>
+<input type="password" name="password" class="passwd" placeholder="password">
+</td></tr>
+
+<tr><td class="links odd" colspan="2">
+<button>Login</button>
+</td></tr>
+
+</table>
</form>
+
{{template "footer.tpl"}}
diff --git a/ii-node/tpl/profile.tpl b/ii-node/tpl/profile.tpl
@@ -0,0 +1,10 @@
+{{template "header.tpl"}}
+
+<table id="profile" cellspacing=0 cellpadding=0>
+<tr class="odd"><td>Login:</td><td>{{.User.Name}}</td></tr>
+<tr class="even"><td>Auth:</td><td>{{.User.Secret}}</td></tr>
+<tr class="odd"><td>e-mail:</td><td>{{.User.Mail}}</td></tr>
+<tr class="even"><td class="links" colspan="2"><a href="/logout">Logout</a>
+</td></tr>
+</table>
+{{template "footer.tpl"}}
diff --git a/ii-node/web.go b/ii-node/web.go
@@ -84,6 +84,29 @@ func www_login(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request) e
return errors.New("Wrong method")
}
+func www_profile(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request) error {
+ ctx := WebContext{ User: user }
+ ii.Trace.Printf("www profile")
+ if user.Name == "" {
+ ii.Error.Printf("Access denied")
+ return errors.New("Access denied")
+ }
+ err := www.tpl.ExecuteTemplate(w, "profile.tpl", ctx)
+ return err
+}
+
+func www_logout(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request) error {
+ ii.Trace.Printf("www logout: %s", user.Name)
+ if user.Name == "" {
+ ii.Error.Printf("Access denied")
+ return errors.New("Access denied")
+ }
+ cookie := http.Cookie{Name: "pauth", Value: "", Expires: time.Unix(0, 0)}
+ http.SetCookie(w, &cookie)
+ http.Redirect(w, r, "/", http.StatusSeeOther)
+ return nil
+}
+
func www_index(user *ii.User, www WWW, w http.ResponseWriter, r *http.Request) error {
ctx := WebContext{ User: user }
@@ -407,6 +430,10 @@ func handleWWW(www WWW, w http.ResponseWriter, r *http.Request) error {
return www_index(user, www, w, r)
} else if path == "login" {
return www_login(user, www, w, r)
+ } else if path == "logout" {
+ return www_logout(user, www, w, r)
+ } else if path == "profile" {
+ return www_profile(user, www, w, r)
} else if path == "register" {
return www_register(user, www, w, r)
} else if ii.IsMsgId(args[0]) {