Permalink
Browse files

Added logout feature.

  • Loading branch information...
1 parent 14fb69a commit a4616c1ce5c78641be333a5ee1327621fb881021 @akoprow akoprow committed Jan 19, 2012
Showing with 34 additions and 12 deletions.
  1. +11 −2 login.opa
  2. +23 −10 webshell.opa
View
@@ -2,16 +2,25 @@
// (c) MLstate, 2011, 2012
// author: Adam Koprowski
+@abstract type Login.user = {guest} or {FbLogin.user fb_user}
+
module Login {
user = UserContext.make({guest})
- function get_current_user() {
+ function Login.user get_current_user() {
UserContext.execute(identity, user)
}
- function set_current_user(new_user) {
+ function set_current_user(Login.user new_user) {
UserContext.change_or_destroy(function (_) { some(new_user) }, user)
}
+ function get_current_user_name() {
+ match (get_current_user()) {
+ case {guest}: "anonymous"
+ case {~fb_user}: FbLogin.get_name(fb_user)
+ }
+ }
+
}
View
@@ -16,13 +16,8 @@ function focus(set) {
}
function prompt() {
- user_name =
- match (Login.get_current_user()) {
- case {guest}: "anonymous"
- case {~fb_user}: FbLogin.get_name(fb_user)
- }
<span class="prompt">
- {"web: {user_name} $ "}
+ {"web: {Login.get_current_user_name()} $ "}
</span>
}
@@ -58,15 +53,33 @@ client function readevalwrite(expr) {
Dom.scroll_to_bottom(Dom.select_window());
}
+function login_box() {
+ function block(content) {
+ <h3 style="float: right">{content}</>
+ }
+ login =
+ prompt = <a>You can sign in with:</>
+ block(<>{prompt}{FbLogin.xhtml}</>)
+ logout =
+ function do_logout(_) {
+ Login.set_current_user({guest})
+ Client.reload()
+ }
+ name = <a>{Login.get_current_user_name()}</>
+ button = WBootstrap.Button.make({ button: <>Logout</>, callback: do_logout}, [])
+ block(<>{button}{name}</>)
+ match (Login.get_current_user()) {
+ case {guest}: login
+ default: logout
+ }
+}
+
function page() {
topbar =
WB.Navigation.topbar(
WB.Layout.fixed(
WB.Navigation.brand(<>webshell</>, none, ignore) <+>
- <h3 style="float: right">
- <a>You can sign in with:</>
- {FbLogin.xhtml}
- </>
+ {login_box()}
)
)
html = WB.Layout.fixed(

0 comments on commit a4616c1

Please sign in to comment.