@ -24,20 +24,26 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
r . Redirect ( "/" )
r . Redirect ( "/" )
return
return
}
}
data [ "IsSigned" ] = true
data [ "IsSigned" ] = true
data [ "SignedUserId" ] = SignedInId ( session )
data [ "SignedUserId" ] = SignedInId ( session )
data [ "SignedUserName" ] = SignedInName ( session )
data [ "SignedUserName" ] = SignedInName ( session )
data [ "PageIsUserDashboard" ] = true
data [ "PageIsUserDashboard" ] = true
data [ "Avatar" ] = SignedInUser ( session ) . Avatar
data [ "Title" ] = "Dashboard"
data [ "Title" ] = "Dashboard"
r . HTML ( 200 , "user/dashboard" , data )
r . HTML ( 200 , "user/dashboard" , data )
}
}
func Profile ( r render . Render ) {
func Profile ( r render . Render , data base . TmplData , session sessions . Session ) {
r . HTML ( 200 , "user/profile" , map [ string ] interface { } {
data [ "Title" ] = "Profile"
"Title" : "Username" ,
} )
data [ "IsSigned" ] = IsSignedIn ( session )
return
// TODO: Need to check view self or others.
user := SignedInUser ( session )
data [ "Avatar" ] = user . Avatar
data [ "Username" ] = user . Name
r . HTML ( 200 , "user/profile" , data )
}
}
func IsSignedIn ( session sessions . Session ) bool {
func IsSignedIn ( session sessions . Session ) bool {
@ -74,6 +80,7 @@ func SignedInUser(session sessions.Session) *models.User {
user , err := models . GetUserById ( id )
user , err := models . GetUserById ( id )
if err != nil {
if err != nil {
log . Error ( "user.SignedInUser: %v" , err )
return nil
return nil
}
}
return user
return user
@ -120,6 +127,17 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render
r . Redirect ( "/" )
r . Redirect ( "/" )
}
}
func SignOut ( r render . Render , session sessions . Session ) {
if ! IsSignedIn ( session ) {
r . Redirect ( "/" )
return
}
session . Delete ( "userId" )
session . Delete ( "userName" )
r . Redirect ( "/" )
}
func SignUp ( form auth . RegisterForm , data base . TmplData , req * http . Request , r render . Render ) {
func SignUp ( form auth . RegisterForm , data base . TmplData , req * http . Request , r render . Render ) {
data [ "Title" ] = "Sign Up"
data [ "Title" ] = "Sign Up"
data [ "PageIsSignUp" ] = true
data [ "PageIsSignUp" ] = true