用户注册
1.如果GET请求则请求html页面,如果POST请求则请求接口
func SignUpHandler(w http.ResponseWriter,r *http.Request){
if r.Method == http.MethodGet{
data,err := ioutil.ReadFile("./static/view/signup.html")
if err != nil {
w.WriteHeader(http.StatusInternalServerError) //500错误
}
w.Write(data)//将html页面输出
}else {
r.ParseForm() //将post来的数据进行解析
username := r.Form.Get("username")
password := r.Form.Get("password")
if (len(username) < 3 || len(password) < 5) {
//对于传递过来的数据进行校验
w.Write([]byte("Invaild paramter"))
return
}
enc_password := util.Sha1([]byte(password + pwd_salt)) //将密码进行加密处理
suc := delay.UserSignUp(username, enc_password) //处理注册逻辑
fmt.Println(suc)
if suc {
w.Write([]byte("success"))
} else {
w.Write([]byte(<