func (c PJ) Edit(inputDay string) revel.Result { common.WriteLogStr("Top", "PushEditButton", "Start", "startDay = "+inputDay) startDay := common.ConvertStrToDay(inputDay) // 該当の進捗情報取得 report := services.GetReport(c.Connected().Id, startDay) if report == nil { // 前回の進捗を取得 lastDay := startDay.AddDate(0, 0, -7) lastReport := services.GetReport(c.Connected().Id, lastDay) // 取得できた場合は、情報をセット if lastReport != nil { report = c.setLastReport(lastReport) } fmt.Print("------- Report.Kotei => " + report.Kotei) } // 日付設定 days := c.setDays(startDay) common.WriteLogStr("Top", "PushEditButton", "End", "startDay = "+startDay.Format(constant.STR_TYPE_LAYOUT)) return c.Render(report, days, inputDay) }
/* ユーザ登録画面.登録ボタン押下処理 */ 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 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()) }