mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	Finish log in user
This commit is contained in:
		
					parent
					
						
							
								d8b92b4bc9
							
						
					
				
			
			
				commit
				
					
						56a7ab4da5
					
				
			
		
					 8 changed files with 104 additions and 58 deletions
				
			
		|  | @ -28,7 +28,7 @@ type RegisterForm struct { | |||
| 	RetypePasswd string `form:"retypepasswd"` | ||||
| } | ||||
| 
 | ||||
| func (r *RegisterForm) Name(field string) string { | ||||
| func (f *RegisterForm) Name(field string) string { | ||||
| 	names := map[string]string{ | ||||
| 		"UserName":     "Username", | ||||
| 		"Email":        "E-mail address", | ||||
|  | @ -38,6 +38,57 @@ func (r *RegisterForm) Name(field string) string { | |||
| 	return names[field] | ||||
| } | ||||
| 
 | ||||
| func (f *RegisterForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { | ||||
| 	if req.Method == "GET" || errors.Count() == 0 { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) | ||||
| 	data["HasError"] = true | ||||
| 	AssignForm(f, data) | ||||
| 
 | ||||
| 	if len(errors.Overall) > 0 { | ||||
| 		for _, err := range errors.Overall { | ||||
| 			log.Error("RegisterForm.Validate: %v", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	validate(errors, data, f) | ||||
| } | ||||
| 
 | ||||
| type LogInForm struct { | ||||
| 	UserName string `form:"username" binding:"Required;AlphaDash;MinSize(5);MaxSize(30)"` | ||||
| 	Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` | ||||
| } | ||||
| 
 | ||||
| func (f *LogInForm) Name(field string) string { | ||||
| 	names := map[string]string{ | ||||
| 		"UserName": "Username", | ||||
| 		"Password": "Password", | ||||
| 	} | ||||
| 	return names[field] | ||||
| } | ||||
| 
 | ||||
| func (f *LogInForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { | ||||
| 	if req.Method == "GET" || errors.Count() == 0 { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) | ||||
| 	data["HasError"] = true | ||||
| 	AssignForm(f, data) | ||||
| 
 | ||||
| 	if len(errors.Overall) > 0 { | ||||
| 		for _, err := range errors.Overall { | ||||
| 			log.Error("LogInForm.Validate: %v", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	validate(errors, data, f) | ||||
| } | ||||
| 
 | ||||
| func getMinMaxSize(field reflect.StructField) string { | ||||
| 	for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { | ||||
| 		if strings.HasPrefix(rule, "MinSize(") || strings.HasPrefix(rule, "MaxSize(") { | ||||
|  | @ -86,25 +137,6 @@ func validate(errors *binding.Errors, data base.TmplData, form Form) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (r *RegisterForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { | ||||
| 	if req.Method == "GET" || errors.Count() == 0 { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) | ||||
| 	data["HasError"] = true | ||||
| 	AssignForm(r, data) | ||||
| 
 | ||||
| 	if len(errors.Overall) > 0 { | ||||
| 		for _, err := range errors.Overall { | ||||
| 			log.Error("RegisterForm.Validate: %v", err) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	validate(errors, data, r) | ||||
| } | ||||
| 
 | ||||
| // AssignForm assign form values back to the template data. | ||||
| func AssignForm(form interface{}, data base.TmplData) { | ||||
| 	typ := reflect.TypeOf(form) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue