/* 初期表示処理 */ func (c PJ) Index() revel.Result { common.WriteLog("Top", "pushLoginButton", "Start") // 取得範囲計算 startRange := time.Now().AddDate(0, 0, -1*constant.RANGE_REPORT_LIST_BEFORE_DAY) endRange := time.Now().AddDate(0, 0, constant.RANGE_REPORT_LIST_AFTER_DAY) // 進捗一覧取得 reportList := services.GetReportList(c.Connected().Id, startRange, endRange) // 進捗一覧整形処理 outputReports := c.arrangeReports(*reportList, startRange, endRange) common.WriteLog("Top", "pushLoginButton", "End") return c.Render(outputReports) }
/* ユーザ登録画面.登録ボタン押下処理 */ func (c Login) SaveUser(user models.User, verifyPassword string) revel.Result { common.WriteLog("Register", "pushLoginButton", "Start") // バリデーションチェック(jsがオフになっているブラウザ対応) c.Validation.Required(verifyPassword) c.Validation.Required(verifyPassword == user.Password). Message("Password does not match") login.Validate(c.Validation, user) if c.Validation.HasErrors() { common.WriteLog("Register", "pushLoginButton", "Validate Error") c.Validation.Keep() c.FlashParams() return c.Redirect(routes.Login.Register()) } // ユーザ名の重複確認 if userData := services.GetUser(user.Username); userData != nil { common.WriteLogStr("Register", "pushLoginButton", "Input Regestered Username", "userName = "******"UserName Already Registred.") return c.Redirect(routes.Login.Register()) } // パスワードのハッシュ化 hassedPass, _ := bcrypt.GenerateFromPassword( *(*[]byte)(unsafe.Pointer(&user.Password)), bcrypt.DefaultCost) user.Password = string(hassedPass) // 登録処理 if err := services.InsertUser(user); err != nil { common.WriteLogStr("Register", "pushLoginButton", "Insert Error", "userName = "******" password = "******"user"] = user.Username c.Flash.Success("登録が完了しました。") c.Flash.Out["username"] = user.Username common.WriteLog("Register", "pushLoginButton", "End") return c.Redirect(routes.Login.Index()) }
func (c PJ) arrangeReports(reportList []models.Report, startRange, endRange time.Time) []forms.Top { rtnList := []forms.Top{} // 最遅出力日算出 d := (int)(endRange.Weekday()) switch d { case 0: d += 6 default: d -= 1 } seekDay := endRange.AddDate(0, 0, d*-1) // 整形処理 newRecord := forms.Top{} // 日付が範囲外になるまでレコードを作成する for seekDay.After(startRange) { newRecord.StartDay = seekDay newRecord.EndDay = seekDay.AddDate(0, 0, 6) // DBからの取得結果に、該当日付が存在する場合 i := c.seekSlice(reportList, seekDay) if i != -1 { fmt.Println("seekDay => " + seekDay.Format("20060102") + " YES") newRecord.Status = "作成済み" // newRecord.UpdateTime = common.ConvertStrToDay(reportList[i].UpdateDay) rtnList = append(rtnList, newRecord) } else { fmt.Println("seekDay => " + seekDay.Format("20060102") + " NO") newRecord.Status = "未作成" rtnList = append(rtnList, newRecord) } seekDay = seekDay.AddDate(0, 0, -7) } common.WriteLog("Top", "Seikei", "End") return rtnList }
/* ログイン画面.ログインボタン押下処理 */ func (c Login)Login(username, password string, remember bool) revel.Result { common.WriteLog("Login", "pushLoginButton", "Start") // ユーザ情報取得 userData := services.GetUser(username) // ユーザが見つからない場合 if userData == nil { common.WriteLogStr("Login", "Login", "Not Found Username", "input userName = "******"username"] = username c.Flash.Error("Login failed") return c.Redirect(routes.Login.Index()) } // パスワードチェック err := bcrypt.CompareHashAndPassword(*(*[]byte)(unsafe.Pointer(&userData.Password)), []byte(password)) // パスワードが間違っている場合 if err != nil { common.WriteLogStr("Login", "Login", "Not Correct Password", "input password = "******"username"] = username c.Flash.Error("Login failed") return c.Redirect(routes.Login.Index()) } c.Session["user"] = username if remember { c.Session.SetDefaultExpiration() } else { c.Session.SetNoExpiration() } common.WriteLogStr("Login", "Login", "End", "Login by " + userData.Username) return c.Redirect(routes.PJ.Index()) }
/* ログイン画面.新規登録ボタン押下処理 */ func (c Login) Register() revel.Result { common.WriteLog("Login", "Register", "") return c.Render() }