Exemple #1
0
// validates to make sure the email format is correct. Also it checks to see if
// the passwords are matching, if not it will return an error message in HTML format
func validate(email, pass1, pass2 string, req *http.Request) []string {
	var err []string
	if valid, _ := regexp.MatchString(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`, email); !valid {
		err = append(err, "Wrong email format")
	}
	if pass1 == "" || pass2 == "" {
		err = append(err, "Password is mandatory")
	}
	if pass1 != pass2 {
		err = append(err, "Passwords do not match")
	}
	if u := util.GetUserWithEmail(email, req); u.Email != "" {
		err = append(err, "User already exists")
	}
	return err
}
Exemple #2
0
// A handler for Ajax calls which writes a JSON on the response back, saying if the user is already taken or not.
func IsUserTaken(res http.ResponseWriter, req *http.Request) {
	userName := req.FormValue("username")
	log.Println("Checking to see if the user [" + userName + "] is already taken...")
	u := util.GetUserWithEmail(userName, req)
	json.NewEncoder(res).Encode(u.Email != "")
}
Exemple #3
0
// Validates to see if the username and password given correct or not
func isValidUser(username, password string, req *http.Request) bool {
	u := util.GetUserWithEmail(username, req)
	return u.Email == username && u.Password == Encrypt(password)
}