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) { AjaxValidator validator = new AjaxValidator(); var id = validator.GetRequiredString(input, "nativeId"); if (validator.IsOk) { // what is it... string asString = id.Substring(id.Length - 2); int asInt = Convert.ToInt32(asString, 16); // which one... string resourceName = string.Format("Mbrit.StreetFoo.Resources.Graffiti{0:d2}.jpg", asInt % 5); var inStream = typeof(FooRuntime).Assembly.GetManifestResourceStream(resourceName); if (inStream == null) throw new InvalidOperationException(string.Format("A resource with name '{0}' was not found.", resourceName)); using (inStream) { using (var outStream = new MemoryStream()) { var bs = new byte[32768]; while (true) { int read = inStream.Read(bs, 0, bs.Length); if (read == 0) break; outStream.Write(bs, 0, read); } // set... output["image"] = Convert.ToBase64String(outStream.ToArray()); } } } // ok... validator.Apply(output); }
protected override void DoRequest(AjaxContext context, JsonData input, JsonData output) { // get... AjaxValidator validator = new AjaxValidator(); string title = validator.GetRequiredString(input, "title"); string description = validator.GetRequiredString(input, "description"); // ok? if (validator.IsOk) { // lat/long - tbd... Report report = Report.CreateReport(context, context.User, title, description, 0, 0); if (report == null) throw new InvalidOperationException("'report' is null."); // set... output["reportId"] = report._id.ToString(); } // 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); }