public async Task <Dictionary <string, object> > Login(CustomerLoginDTO customerDTO) { Dictionary <string, object> res = new Dictionary <string, object>(); if (string.IsNullOrEmpty(customerDTO.Username) || string.IsNullOrEmpty(customerDTO.Password)) { res["status"] = "failed"; res["message"] = "用户名或密码不能为空!"; } else { Customer customer = await Service.Login(customerDTO.Username, customerDTO.Password); if (customer == null) { res["status"] = "failed"; res["message"] = "用户名或密码错误!"; } else { res["status"] = "success"; res["token"] = JWTTools.Encode(customer.Username, DateTime.Now.AddDays(1)); } } return(res); }
public async Task <Dictionary <string, object> > Login(Administrator administrator) { Dictionary <string, object> res = new Dictionary <string, object>(); Administrator tmp = await Service.Login(administrator); if (tmp == null) { res["status"] = "failed"; res["message"] = "用户名或密码错误!"; } else { res["status"] = "success"; res["token"] = JWTTools.Encode(tmp.Username, DateTime.Now.AddDays(1), true); } return(res); }
public ResultModel Login([FromBody] LoginViewModel model) { ResultModel res = new ResultModel(); User user = UserService.SelectUser(model.ID, model.identity); if (user == null) { res.status = "500"; res.insert("msg", "用户不存在"); } else if (Encryption.MD5Encryption(model.password).Equals(user.password)) { res.status = "200"; res.insert("loginToken", JWTTools.Encode(model, JWTTools.secret)); res.insert("user", user); } else { res.status = "500"; res.insert("msg", "密码错误"); } return(res); }