Skip to content

Commit

Permalink
Merge pull request #23 from Team6083/develop
Browse files Browse the repository at this point in the history
Prepare Release 1.2.5
  • Loading branch information
kennhung authored Aug 7, 2019
2 parents b08a305 + b593641 commit 68f421c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- run:
name: Sentry release
command: |
VERSION="[email protected].4"
VERSION="[email protected].5"
echo $VERSION
sentry-cli releases new -p overhours $VERSION
sentry-cli releases set-commits --auto $VERSION
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<div class="ml-md-5 ml-2 mr-md-5 mr-2">
<hr>
<div class="text-center">
<p>OverHours 1.2.4 | <a class="badge-pill badge badge-warning"
<p>OverHours 1.2.5 | <a class="badge-pill badge badge-warning"
href="https://github.com/Team6083/OverHours/issues">Bugs report</a></p>
</div>
</div>
Expand Down
25 changes: 23 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ <h4>Current login: <span class="badge badge-dark">{{.UserName}}</span> / Season:
class="badge badge-primary badge-pill">{{.CurrentSeason}}</span></h4>
<form method="post" action="/timeLog/checkinPost">
<div class="input-group mb-3 mt-3">
<input type="text" class="form-control" name="studentId" placeholder="Students's Id"
<input type="text" class="form-control" id="usernameInput" name="studentId" placeholder="Students's Id"
value="{{.UserAccName}}" {{.Readonly}}>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit"
id="stu-submit" {{if eq .CanCheckIn false}} disabled {{end}}>Checkin
</button>
{{if eq .Disable false}}
<button class="btn btn-outline-dark dropdown-toggle dropdown-toggle-split" type="button"
data-toggle="dropdown">
<span class="sr-only">Select...</span>
</button>
<div class="dropdown-menu" id="usernameDropdown">

</div>
{{end}}
</div>
</div>
</form>
Expand Down Expand Up @@ -46,7 +55,8 @@ <h4>Current login: <span class="badge badge-dark">{{.UserName}}</span> / Season:
<div class="card border-info text-center">
<div class="card-body">
<h6 class="card-title">Incoming meeting can start checkin now</h6>
<a class="btn btn-outline-primary" href="/meeting/detail/{{.IncomingMeet.MeetId}}">{{.IncomingMeet.Title}}</a>
<a class="btn btn-outline-primary"
href="/meeting/detail/{{.IncomingMeet.MeetId}}">{{.IncomingMeet.Title}}</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -149,6 +159,17 @@ <h6 class="card-title">Incoming meeting can start checkin now</h6>

</script>

<script>
for (let key in names) {
$("#usernameDropdown").append("<a class=\"dropdown-item usernameSelect\" value=\"" + key + "\">" + names[key] + "</a>")
}

$(".usernameSelect").on('click', function () {
let username = $(this).attr('value');
$("#usernameInput").val(username);
});
</script>


{{end}}

Expand Down
6 changes: 5 additions & 1 deletion templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ <h2>Login</h2>
placeholder="Password">
</div>
{{if ne .Redirect ""}}<input type="hidden" name="redirect" value="{{.Redirect}}">{{end}}
<button type="submit" class="btn btn-primary">Submit</button>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="rememberMe" id="rememberMe">
<label for="rememberMe" class="custom-control-label">Remember me</label>
</div>
<button type="submit" class="btn btn-primary mt-2">Submit</button>
</form>
</div>
</div>
Expand Down
54 changes: 41 additions & 13 deletions web/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package web

import (
"errors"
"fmt"
"github.com/Team6083/OverHours/models"
"github.com/satori/go.uuid"
"gopkg.in/mgo.v2"
Expand Down Expand Up @@ -67,25 +68,39 @@ func getSessionTokenCookie(r *http.Request) (*string, error) {
}

func setSessionTokenCookie(w http.ResponseWriter, session LoginSession) {
http.SetCookie(w, &http.Cookie{

expTime := time.Unix(session.Validate, 0)

sessionCookie := http.Cookie{
Name: "session_jwt",
Value: session.SessionToken,
Path: "/",
Expires: time.Unix(session.Validate, 0),
HttpOnly: true,
})
}

http.SetCookie(w, &http.Cookie{
Name: "userName",
Value: session.Username,
Path: "/",
Expires: time.Unix(session.Validate, 0),
})
usernameCookie := http.Cookie{
Name: "userName",
Value: session.Username,
Path: "/",
}

fmt.Println(session.Validate)

if session.Validate == 0 {
expTime = time.Now().Add(168 * time.Hour)
}

sessionCookie.Expires = expTime
usernameCookie.Expires = expTime

http.SetCookie(w, &sessionCookie)

http.SetCookie(w, &usernameCookie)
}

func resetSessionCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{
Name: "session_token",
Name: "session_jwt",
Value: "",
Path: "/",
Expires: time.Now(),
Expand Down Expand Up @@ -125,7 +140,7 @@ func (web *Web) checkAuth(w http.ResponseWriter, r *http.Request) (*LoginSession
return nil, err
}

if result.Validate < time.Now().Unix() {
if result.Validate < time.Now().Unix() && result.Validate != 0 {
return nil, AuthTimeExpired
}

Expand Down Expand Up @@ -311,6 +326,12 @@ func (web *Web) LoginPOST(w http.ResponseWriter, r *http.Request) {
return
}

rememberMe := false

if r.Form["rememberMe"] != nil && r.Form["rememberMe"][0] == "on" {
rememberMe = true
}

cred.Username = r.Form["loginUsername"][0]
cred.Password = r.Form["loginPassword"][0]

Expand All @@ -335,7 +356,10 @@ func (web *Web) LoginPOST(w http.ResponseWriter, r *http.Request) {

loginSession := newLoginSession(cred.Username)

// Finally, we set the client cookie for "session_token" as the session token we just generated
if rememberMe {
loginSession.Validate = 0
}

setSessionTokenCookie(w, *loginSession)

_, err = web.storeSession(loginSession)
Expand Down Expand Up @@ -368,14 +392,18 @@ func newLoginSession(username string) *LoginSession {
session.Username = username
session.SessionToken = newSessionToken()
session.Validate = time.Now().Add(sessionTimeout).Unix()

return session
}

func (session *LoginSession) renew(onlyTime bool) {
if !onlyTime {
session.SessionToken = newSessionToken()
}
session.Validate = time.Now().Add(sessionTimeout).Unix()

if session.Validate != 0 {
session.Validate = time.Now().Add(sessionTimeout).Unix()
}
}

func newSessionToken() string {
Expand Down

0 comments on commit 68f421c

Please sign in to comment.