public async Task <APIResponseModel> Process(SampleUser userContext, UserSiteInfoAction action) { UserModel user = null; if (userContext.SiteUser != null) { user = userContext.OBO != null ? userContext.OBO : userContext.SiteUser; } if (user.SiteSettings == null) { user.SiteSettings = new UserSiteInfoModel(); } foreach (var kvp in action.Settings) { if (user.SiteSettings.Settings.ContainsKey(kvp.Key)) { user.SiteSettings.Settings[kvp.Key] = kvp.Value; } else { user.SiteSettings.Settings.Add(kvp.Key, kvp.Value); } } var dte = UserEntity.UpdateSiteBuilder(user.UserId, user.SiteSettings); var rs = await this.DataManager.UpdateEntityProperty(EntityTableType.user, dte); if (rs.Code != ResponseCode.Ok) { return(APIResponseModel.Error(rs.Code, rs.Message)); } return(APIResponseModel.ResultWithData(ResponseType.SiteInfo, new UserSiteInfoViewModel(user.SiteSettings))); }
public async Task Config() { //do something var response = !this.DataManager.Loaded(DataManagerDataType.System) ? APIResponseModel.Error(ResponseCode.Loading) : APIResponseModel.ResultWithData(ResponseType.Metadata, new MetadataViewModel(this.DataManager.Metadata)); await Clients.Caller.SendAsync("config", response.ToJson()); }
public async Task <APIResponseModel> Process(UserSignupAction action) { // just be safe action.Email = action.Email.ToLower(); if (string.IsNullOrWhiteSpace(action.Email)) { return(APIResponseModel.Error(ResponseCode.InvalidParameter, "Email")); } if (string.IsNullOrWhiteSpace(action.Password)) { return(APIResponseModel.Error(ResponseCode.InvalidParameter, "Password")); } if (action.Language == LanguageId.None) { action.Language = LanguageId.en; } var passwordStrength = new PasswordStrengthValidator().Test(action.Password); if (!passwordStrength.Good) { return(APIResponseModel.Error(ResponseCode.InvalidParameter, "Password Strength")); } // prepare the user UserPasswordModel password = new UserPasswordModel(await this.PasswordManager.CreatePasswordHash(action.Password)); UserModel user = UserModel.Create(UserType.Standard, UserStatusId.Registered, action.Language, action.Email, password, action.DisplayName); var rs = await this.DataManager.CreateUserAsync(user); // failed - get out if (rs.Code != ResponseCode.Ok) { //await this.DataManager.LogEventAsync( LogEventModel.Failure( action.Action, user.ToJson(), user.UserId ) ); return(APIResponseModel.Result(rs)); } try { var j = new Newtonsoft.Json.Linq.JObject( new Newtonsoft.Json.Linq.JProperty("userId", user.UserId.Encode()), new Newtonsoft.Json.Linq.JProperty("email", user.Email ?? "{null}"), new Newtonsoft.Json.Linq.JProperty("name", user.Name ?? "{null}") ).ToString(Newtonsoft.Json.Formatting.Indented); this.DataManager.WriteEvent("user-created", j); // don't await - fire & forget } catch { } // move everything from the email address to the user try { rs = await this.DataManager.ConvertEmailToUserId(user); if (rs.Code != ResponseCode.Ok) { await this.DataManager.LogErrorAsync("Process(UserSignupAction)", rs.ToJson()); } } catch (Exception ex) { this.DataManager.LogExceptionAsync("Process(UserSignupAction)", ex); } // pipeline the email verification request try { APIResponseModel rs1 = await this.Process(new InternalSendEmailVerificationAction() { UserId = user.UserId }); } catch (Exception ex) { this.DataManager.LogErrorAsync("InternalSendEmailVerificationAction", ex.Message + Environment.NewLine + (ex.StackTrace ?? string.Empty)); } this.SlackProvider.Send($"New user! {action.Email}"); //fire and forget ResponseData response = new ResponseData(); response.Add(ResponseType.User, new UserViewModel(user)); return(APIResponseModel.ResultWithData(response)); }