rename auth service
This commit is contained in:
@@ -100,13 +100,13 @@ func (bf *BookForm) IsSuccess() bool {
|
||||
return bf.Method == http.MethodPost && bf.Error == "" && !bf.HasErrors()
|
||||
}
|
||||
|
||||
func Handler(s *services.SessionStore) func(http.ResponseWriter, *http.Request) {
|
||||
func Handler(a services.IAuthenticate) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
getUploadFile(w, r)
|
||||
case http.MethodPost:
|
||||
postUploadFile(w, r, s)
|
||||
postUploadFile(w, r, a)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
@@ -164,10 +164,10 @@ func extractBookForm(r *http.Request) BookForm {
|
||||
return bf
|
||||
}
|
||||
|
||||
func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionStore) {
|
||||
func postUploadFile(w http.ResponseWriter, r *http.Request, a services.IAuthenticate) {
|
||||
uploadForm := templates.GetUploadForm()
|
||||
|
||||
if !s.IsLogged(r) {
|
||||
if !a.IsLogged(r) {
|
||||
buf := bytes.NewBufferString("")
|
||||
if err := uploadForm.Execute(buf, &BookForm{Error: services.ErrUnauthorized.Error()}); err != nil {
|
||||
log.Err(err).Msg("unable to generate template")
|
||||
@@ -179,8 +179,8 @@ func postUploadFile(w http.ResponseWriter, r *http.Request, s *services.SessionS
|
||||
return
|
||||
}
|
||||
|
||||
buf := bytes.NewBufferString("")
|
||||
bf := extractBookForm(r)
|
||||
buf := bytes.NewBufferString("")
|
||||
if err := uploadForm.Execute(buf, &bf); err != nil {
|
||||
log.Err(err).Msg("unable to generate template")
|
||||
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
||||
@@ -241,8 +241,5 @@ func getUploadFile(w http.ResponseWriter, _ *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, buf); err != nil {
|
||||
log.Err(err).Msg("unable to write to response")
|
||||
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
||||
}
|
||||
fmt.Fprint(w, buf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user