/// <summary> /// Replaces any existing user profile with a specified one. /// </summary> /// <param name="profile"></param> public static void InitializeUserProfile(UserProfile profile) { _userProfile = profile; }
/// <summary> /// Sends a user's profile to the master server. /// </summary> /// <param name="profile">The user's profile containing username, password, email, etc.</param> /// <param name="createNewProfile">If true, the account will attempt to be created. If false, it will be updated.</param> /// <returns></returns> public UserProfileResponseTypeEnum SendUserProfile(UserProfile profile, bool createNewProfile) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); string jsonObject = serializer.Serialize(profile); string result; if(createNewProfile) { result = SendJsonRequest("CreateUserProfile", WebServiceMethodTypeEnum.User, jsonObject); } else { result = SendJsonRequest("UpdateUserProfile", WebServiceMethodTypeEnum.User, jsonObject); } return serializer.Deserialize<UserProfileResponseTypeEnum>(result); } catch (Exception ex) { throw new Exception("Error sending user profile.", ex); } }
/// <summary> /// Attempts to create a new user profile on the master server. /// Can fail for any of the following reasons: /// - Username already exists /// - Invalid password /// - Password mismatch /// - Email address already in use /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void SaveUserProfileClickAsync(object sender, JavascriptMethodEventArgs args) { UserProfileResponseTypeEnum responseType = UserProfileResponseTypeEnum.Failure; string password = args.Arguments[1]; string confirmPassword = args.Arguments[2]; bool isCreatingNewProfile = (bool)args.Arguments[7]; await TaskEx.Run(() => { if (password == confirmPassword) { UserProfile profile = new UserProfile { UserName = args.Arguments[0], UserPassword = args.Arguments[1], UserEmail = args.Arguments[3], UserFirstName = args.Arguments[4], UserLastName = args.Arguments[5], }; DateTime parsedDOB; DateTime.TryParse(args.Arguments[6], out parsedDOB); profile.UserDOB = parsedDOB; responseType = WebUtility.SendUserProfile(profile, isCreatingNewProfile); } else { responseType = UserProfileResponseTypeEnum.PasswordMismatch; } }); AsyncJavascriptCallback("SaveProfileButton_Callback", Convert.ToInt32(responseType)); }