public object login(LoginInput input) { var user = (from u in this.db.users where u.username == input.username select u).FirstOrDefault(); if (user != null) { if (user.password == input.password) { var token = new JwtBuilder() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSecret(Config.secret) .AddClaim("userId", user.id) .Build(); return(CommonRtn.Success("user", user)); } else { return(CommonRtn.Error("密码错误")); } } else { return(CommonRtn.Error("用户不存在")); } }
public CommonRtn signup([FromBody] LoginInput input) { var user = (from u in this.db.users where u.username == input.username select u).FirstOrDefault(); if (user != null) { return(CommonRtn.Error("用户已经注册")); } else { var newUser = new User { nickname = "新用户", username = input.username, password = input.password, roleType = RoleType.User }; this.db.users.Add(newUser); this.db.SaveChanges(); return(CommonRtn.Success(new Dictionary <string, object> { { "user", newUser } })); } }