public CreateUpdateNoteResponse CreateNote([FromBody] CreateNoteAction createNote) { CreateUpdateNoteResponse response = new CreateUpdateNoteResponse(); response.Status = string.Empty; if (string.IsNullOrEmpty(createNote.Email)) { return(response); } using (RequestTracker request = new RequestTracker(Constant.RequestAPI.CreateNote.ToString(), createNote.Email)) { try { if (string.IsNullOrEmpty(createNote.Email) || string.IsNullOrEmpty(createNote.AuthToken) || string.IsNullOrEmpty(createNote.NoteContents)) { request.response = RequestTracker.RequestResponse.UserError; return(response); } if (createNote.NoteContents.Length > Constant.MaxNoteLength) { request.response = RequestTracker.RequestResponse.UserError; response.Status = "TooLong"; return(response); } // Use the email and authToken to get the userId string userId = UserController.GetUserId(createNote.Email, createNote.AuthToken); if (string.IsNullOrEmpty(userId)) { request.response = RequestTracker.RequestResponse.UserError; // Expired AuthToken response.Status = "Expired"; return(response); } response.Note = NoteModel.AddNote(createNote.NoteContents, createNote.City, createNote.Latitude, createNote.Longitude, createNote.Email, userId); LastUpdateModel.SetLastUpdate(userId); response.Status = "Success"; return(response); } catch (Exception e) { request.response = RequestTracker.RequestResponse.ServerError; ExceptionTracker.LogException(e); return(response); } } }
/// <summary> /// Create a simple note only indexed on #feedback /// This allows developer (that's you) to still use the app like normal /// </summary> public static void CreateFeedbackNote(DateTime timestamp, string feedbackMessage) { // Only add an index for #feedback NoteModel.AddNote(feedbackMessage, string.Empty, 0F, 0F, string.Empty, Constant.DeveloperId); }
public CreateUserResponse CreateUser([FromBody] CreateUserRequest userRequest) { CreateUserResponse response = new CreateUserResponse(); if (string.IsNullOrEmpty(userRequest.Email)) { response.Error = "Invalid Input"; return(response); } using (RequestTracker request = new RequestTracker(Constant.RequestAPI.CreateUser.ToString(), userRequest.Email)) { try { if (userRequest == null) { request.response = RequestTracker.RequestResponse.UserError; response.Error = "Invalid Input"; return(response); } if (string.IsNullOrEmpty(userRequest.Password) || userRequest.Password.Length < 8) { request.response = RequestTracker.RequestResponse.UserError; response.Error = "Password must be at least 8 characters"; return(response); } if (string.IsNullOrEmpty(userRequest.Email) || !userRequest.Email.Contains("@") || !userRequest.Email.Contains(".")) { request.response = RequestTracker.RequestResponse.UserError; response.Error = "Invalid email address"; return(response); } UserModel retrievedUser; if (UserModel.GetUser(userRequest.Email, out retrievedUser)) { if (!retrievedUser.AuthCheck(userRequest.Password)) { // User exists and pw is wrong request.response = RequestTracker.RequestResponse.UserError; response.Error = "User already exists"; return(response); } else { // Just let user login // Generate temporary auth token string loginToken = retrievedUser.GetAuthToken(); // Store with updated auth table UserModel.UpdateUser(retrievedUser); request.response = RequestTracker.RequestResponse.LoginOnSignup; response.Token = loginToken; response.Error = "Success"; return(response); } } UserModel user = new UserModel(userRequest.Email, userRequest.Password); LastUpdateModel.SetLastUpdate(user.UserId); // Generate temporary auth token string token = user.GetAuthToken(); user.Save(); // Create the tutorial notes foreach (string note in Constant.TutorialNotes) { NoteModel.AddNote(note, string.Empty, 0F, 0F, user.Email, user.UserId); } response.Token = token; response.Error = "Success"; return(response); } catch (Exception e) { request.response = RequestTracker.RequestResponse.ServerError; ExceptionTracker.LogException(e); response.Error = "Server Error"; return(response); } } }