protected override void DoRequest(AjaxContext context, JsonData input, JsonData output) { // get... AjaxValidator validator = new AjaxValidator(); string username = validator.GetRequiredString(input, "username"); string password = validator.GetRequiredString(input, "password"); // ok? if (validator.IsOk) { // get... User user = User.GetByUsername(context, username); if (user != null) { // check... if (user.CheckPassword(password)) { // create an access token... Token token = Token.CreateToken(context, user); if (token == null) throw new InvalidOperationException("'token' is null."); // set... output["token"] = token.TheToken; } else validator.AddError("Password is invalid."); } else validator.AddError("Username is invalid."); } // set... validator.Apply(output); }
protected override void DoRequest(AjaxContext context, JsonData input, JsonData output) { // get... AjaxValidator validator = new AjaxValidator(); string username = validator.GetRequiredString(input, "username"); string email = validator.GetRequiredString(input, "email"); string password = validator.GetRequiredString(input, "password"); string confirm = validator.GetRequiredString(input, "confirm"); // check... if (validator.IsOk) { if (!(string.IsNullOrEmpty(password)) && password != confirm) validator.AddError("Passwords do not match."); } // ok? if (validator.IsOk) { // get... User user = User.GetByUsername(context, username); if (user == null) { user = User.CreateUser(context, username, email, password); if (user == null) throw new InvalidOperationException("'user' is null."); // set... output["userId"] = user._id.ToString(); } else validator.AddError("Username already in use."); } // set... validator.Apply(output); }