//public dynamic Postusers(dynamic data) public dynamic resetPassword(FormUsersResetPassword data) { List <string> errList = new List <string>(); if (!db.users.Any(o => o.userID == data.userID)) { errList.Add("userNotExistErr"); return(JsonTool.toJson(errList)); } var user = (from p in db.users where p.userID == data.userID select p).SingleOrDefault(); int status = (int)user.status; if (status == -1) { errList.Add("userBannedErr"); return(JsonTool.toJson(errList)); } if (status == 0) { errList.Add("userNotActivateErr"); return(JsonTool.toJson(errList)); } foreach (ModelState modelState in ModelState.Values) { foreach (ModelError error in modelState.Errors) { errList.Add(error.ErrorMessage.ToString()); } } if (errList.Count > 0) { return(JsonTool.toJson(errList)); } user.password = HashTool.getHash(data.password); UsersCmd.changePassword(user); return(JsonTool.toJson(user)); }
public dynamic userRegister(FormUsersRegister data) { List <string> errList = new List <string>(); foreach (ModelState modelState in ModelState.Values) { foreach (ModelError error in modelState.Errors) { errList.Add(error.ErrorMessage.ToString()); } } if (db.users.Any(o => o.email == data.email)) { errList.Add("emailExistErr"); } if (db.users.Any(o => o.nickname == data.nickname)) { errList.Add("nicknameExistErr"); } if (errList.Count > 0) { return(JsonTool.toJson(errList)); } users newOne = new users { email = data.email, nickname = data.nickname, password = HashTool.getHash(data.password), gender = data.gender, birthDate = DateTime.ParseExact(data.birthDate.Replace("-", "/"), "yyyy/MM/dd", CultureInfo.InvariantCulture), createAt = DateTime.Now, updateAt = DateTime.Now }; if (UsersCmd.insert(newOne) <= 0) { errList.Add("dbInsertErr"); return(JsonTool.toJson(errList)); } ; newOne.userID = (from p in db.users where p.email == data.email select p).SingleOrDefault().userID; //send verify email string baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); UsersEmail.sendValidateEmail(newOne, baseUrl); var obj = ( from p in db.users where p.userID == newOne.userID select new { p.userID, p.email, p.nickname, p.gender, p.birthDate, p.createAt } ).SingleOrDefault(); return(JsonTool.toJson(obj)); }