Ejemplo n.º 1
0
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	result := Result{}
	//	logErr  := logger.GetErr()
	//	logInfo := logger.GetInfo()

	fmt.Println("login", r.Method)
	if r.Method == "GET" {
		//do something
		//这里不需要执行,没有路由使用这个路由下的 GET 方法

	} else {
		loginInfo := LoginerStruct{}

		loginInfo.username = r.FormValue("loginName")
		loginInfo.passw = r.FormValue("loginPassw")

		//status = 1,用户名或密码为空
		//status = 2,数据库访问出错
		//status = 3,登陆成功

		if loginInfo.username == "" || loginInfo.passw == "" {
			result.Status = 1
			result.Msg = res_type_info.name_or_pass_not_empty
			logInfo.Println(res_type_info.name_or_pass_not_empty)
			common.OutPut_Result(w, result)
			return
		}

		res, err := userLoginFunc(loginInfo)
		if err != nil {

			logErr.Println(err)
			fmt.Println(err)
			result.Status = 2
			result.Msg = res_type_info.System_error

		} else if res == false {

			fmt.Println("login failed,the result is password isn't current")
			result.Status = 3
			result.Msg = res_type_info.Password_error

		} else {

			logInfo.Println(loginInfo.username + " login succeed")
			result.Status = 4
			result.Msg = res_type_info.login_suc

		}
		common.OutPut_Result(w, result)
		return
	}
}
Ejemplo n.º 2
0
func RegisterHandler(w http.ResponseWriter, r *http.Request) {

	fmt.Println(r.Method)

	if r.Method == "GET" {
		reg_Info := Reg_Type_Info{
			IsHide:   "none",
			Info:     "",
			BackShow: false,
		}

		file, err := template.ParseFiles("../www/html/register.html")
		if err != nil {
			logErr.Println("ParseFile register.html failed")
			return
		}

		file.Execute(w, reg_Info)

	} else {
		logInfo.Println("A user begin register.")
		register_user := RegisterStruct{}
		result := Result{}

		r.ParseForm()
		register_user.Username = r.FormValue("username")
		register_user.Psw1 = r.FormValue("passwd1")
		register_user.Psw2 = r.FormValue("passwd2")
		register_user.Email = r.FormValue("email")
		if register_user.Psw1 != register_user.Psw2 {
			logWar.Println("psw1 is not equal psw2.")
			result.Status = 1
			result.Msg = "password input isn't equal twice"
			common.OutPut_Result(w, result)
			fmt.Println("register failed")
			return
		}

		if register_user.Username == "" || register_user.Psw1 == "" || register_user.Psw2 == "" || register_user.Email == "" {
			logWar.Println("input message isn't allowed empty")
			result.Status = 2
			result.Msg = "input message isn't allowed empty"
			common.OutPut_Result(w, result)
			fmt.Println("register failed")
			return
		}

		res, err := register_User(register_user)
		if err != nil {
			result.Status = 3
			result.Msg = "register failed"
			logErr.Println(err)
			fmt.Println(err)
			common.OutPut_Result(w, result)
			return
		}

		result.Status = 4
		if res != "" {
			result.Msg = res
		} else {
			result.Msg = "Register success"
			logInfo.Println("Register success")
		}
		common.OutPut_Result(w, result)
	}
}