//[ValidateAntiForgeryToken] public async Task <IActionResult> SignIn([FromBody] LoginViewModel model, [FromRoute] string returnUrl = null) { if (!ModelState.IsValid) { return(RespondFailure(model)); } var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe })); } if (result.Succeeded) { string anonymousBasketId = Request.Cookies[Constants.BASKET_COOKIENAME]; if (!String.IsNullOrEmpty(anonymousBasketId)) { await _basketService.TransferBasketAsync(anonymousBasketId, model.Email); Response.Cookies.Delete(Constants.BASKET_COOKIENAME); } var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, model.Email), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var token = new JwtSecurityToken ( issuer: _configuration["Token:Issuer"], audience: _configuration["Token:Audience"], claims: claims, expires: DateTime.UtcNow.AddDays(60), notBefore: DateTime.UtcNow, signingCredentials: new SigningCredentials(new SymmetricSecurityKey (Encoding.UTF8.GetBytes(_configuration["Token:Key"])), SecurityAlgorithms.HmacSha256) ); var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { throw new ApplicationException($"Unable to load user with email '{model.Email}'."); } return(RespondSuccess(new { token = new JwtSecurityTokenHandler().WriteToken(token), result, user })); } VerboseReporter.ReportError(string.Empty, "Invalid login attempt."); return(RespondFailure(model)); }
public IHttpActionResult UploadPictures() { var files = HttpContext.Current.Request.Files; if (files.Count == 0) { VerboseReporter.ReportError("No file uploaded", "upload_pictures"); return(RespondFailure()); } var newImages = new List <object>(); for (var index = 0; index < files.Count; index++) { //the file var file = files[index]; //and it's name var fileName = file.FileName; //stream to read the bytes var stream = file.InputStream; var pictureBytes = new byte[stream.Length]; stream.Read(pictureBytes, 0, pictureBytes.Length); //file extension and it's type var fileExtension = Path.GetExtension(fileName); if (!string.IsNullOrEmpty(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } var contentType = file.ContentType; if (string.IsNullOrEmpty(contentType)) { contentType = PictureUtility.GetContentType(fileExtension); } var picture = new Media() { Binary = pictureBytes, MimeType = contentType, Name = fileName }; _mediaService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation); newImages.Add(new { ImageUrl = _mediaService.GetPictureUrl(picture.Id), ThumbnailUrl = _mediaService.GetPictureUrl(picture.Id, PictureSizeNames.ThumbnailImage), ImageId = picture.Id, MimeType = contentType }); } return(RespondSuccess(new { Images = newImages })); }
public IActionResult Delete(int id) { if (id <= 0) { return(RespondFailure()); } _newsCategoryService.Delete(x => x.Id == id); VerboseReporter.ReportSuccess("Xóa danh mục thành công", "delete"); return(RespondSuccess()); }
public IHttpActionResult Post(SecuritySettingsModel entityModel) { var securitySettings = new SecuritySettings() { DefaultPasswordStorageFormat = entityModel.DefaultPasswordStorageFormat }; _settingService.Save(securitySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { SecuritySettings = securitySettings.ToModel() })); }
public IHttpActionResult Post(DateTimeSettingsModel entityModel) { var dateTimeSettings = new DateTimeSettings() { DefaultTimeZoneId = entityModel.DefaultTimeZoneId }; _settingService.Save(dateTimeSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { DateTimeSettings = dateTimeSettings.ToModel() })); }
public IHttpActionResult Post(UrlSettingsModel entityModel) { var thirdPartySettings = new UrlSettings() { ActivationPageUrl = entityModel.ActivationPageUrl }; _settingService.Save(thirdPartySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { ThirdPartySettings = thirdPartySettings.ToModel() })); }
public IHttpActionResult Post(UserSettingsModel entityModel) { var userSettings = new UserSettings() { AreUserNamesEnabled = entityModel.AreUserNamesEnabled, UserRegistrationDefaultMode = entityModel.UserRegistrationDefaultMode }; _settingService.Save(userSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { UserSettings = userSettings.ToModel() })); }
public IHttpActionResult Put(UserEntityPublicModel entityModel) { var user = _userService.Get(entityModel.Id); if (user == null) { return(NotFound()); } //check if the email has already been registered var emailUser = _userService.Get(x => x.Email == entityModel.Email, null).FirstOrDefault(); if (emailUser != null && emailUser.Id != user.Id) { VerboseReporter.ReportError("The email is already registered with another user", "post_user"); return(RespondFailure()); } //same for user name if (_userSettings.AreUserNamesEnabled) { var userNameUser = _userService.Get(x => x.UserName == entityModel.UserName, null).FirstOrDefault(); if (userNameUser != null && userNameUser.Id != user.Id) { VerboseReporter.ReportError("The username is already taken by another user", "post_user"); return(RespondFailure()); } } user.FirstName = entityModel.FirstName; user.LastName = entityModel.LastName; user.Email = entityModel.Email; user.DateUpdated = DateTime.UtcNow; user.Name = string.Concat(user.FirstName, " ", user.LastName); user.UserName = entityModel.UserName; _userService.Update(user); //any images to assign if (entityModel.CoverImageId != 0) { user.SetPropertyValue(PropertyNames.DefaultCoverId, entityModel.CoverImageId); } if (entityModel.ProfileImageId != 0) { user.SetPropertyValue(PropertyNames.DefaultPictureId, entityModel.ProfileImageId); } VerboseReporter.ReportSuccess("Successfully saved profile", "post_user"); return(RespondSuccess(new { User = user.ToEntityPublicModel(_mediaService, _mediaSettings) })); }
public IActionResult Put(EmailMessage entityModel) { var emailMessage = _emailService.FirstOrDefault(x => x.Id == entityModel.Id); //save it and respond //_emailService.Update(emailMessage); VerboseReporter.ReportSuccess("Sửa EmailMessage thành công", "post"); return(RespondSuccess(emailMessage)); }
public IHttpActionResult Delete(int id) { var setting = _settingService.Get(id); if (setting == null) { VerboseReporter.ReportError("Setting not found", "delete_setting"); return(RespondFailure()); } _settingService.Delete(setting); VerboseReporter.ReportSuccess("Setting deleted successfully", "delete_setting"); return(RespondSuccess()); }
public IActionResult Post(NewsCategoryModel entityModel) { //if (!ModelState.IsValid) // return BadRequest(); var newsCategory = entityModel.ToEntity(); //save it _newsCategoryService.Insert(newsCategory); VerboseReporter.ReportSuccess("Tạo danh mục thành công", "post"); return(RespondSuccess(entityModel )); }
protected virtual void InsertLocales(NewsItem newsItem, NewsItemModel newsItemModel) { if (newsItemModel.LanguageId <= 0) { return; } newsItemModel.Locales.Add(new NewsItemLocalizedModel() { LanguageId = newsItemModel.LanguageId, Name = newsItemModel.Name, }); foreach (var localized in newsItemModel.Locales) { //ILocalizedPropertyService.SaveLocalizedValue(NewsItem, // x => x.Name, // localized.Name, // localized.LanguageId); #region LocalizedProperty _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "title", LocaleValue = newsItem.Name }); _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "summary", LocaleValue = newsItem.Short }); _localizedPropertyService.InsertLocalizedProperty(new LocalizedProperty() { EntityId = newsItem.Id, LanguageId = localized.LanguageId, LocaleKeyGroup = "NewsItem", LocaleKey = "content", LocaleValue = newsItem.Full }); #endregion ////search engine name //var seName = NewsItem.ValidateSeName(localized.SeName, localized.Name, false); //_urlRecordService.SaveSlug(NewsItem, seName, localized.LanguageId); } VerboseReporter.ReportSuccess("Sửa ngôn ngữ tin tức thành công", "put"); }
public IHttpActionResult Login(LoginModel loginModel) { var redirect = false; if (loginModel == null || !ModelState.IsValid) { if (!ModelState.IsValid && loginModel != null) { redirect = loginModel.Redirect; } if (!redirect) { VerboseReporter.ReportError("The email or password is invalid", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); } redirect = loginModel.Redirect; if (!ShouldSignIn(loginModel.Email, loginModel.Password)) { if (!redirect) { VerboseReporter.ReportError("The email or password is invalid", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); } //sign in the current user var loginStatus = ApplicationContext.Current.SignIn(loginModel.Email, loginModel.Persist); if (loginStatus == LoginStatus.Success) { if (!redirect) { VerboseReporter.ReportSuccess("Your login was successful", "login"); return(RespondSuccess(new { ReturnUrl = loginModel.ReturnUrl })); } return(RespondRedirect(loginModel.ReturnUrl)); } if (!redirect) { VerboseReporter.ReportError("The login attempt failed due to unknown error", "login"); return(RespondFailure()); } return(RespondRedirect(Request.RequestUri)); }
public IActionResult Delete(int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id <= 0) { return(RespondFailure()); } _categoryService.Delete(x => x.Id == id); VerboseReporter.ReportSuccess("Xóa danh mục thành công", "delete"); return(RespondSuccess()); }
public IActionResult Post(LocalizedProperty model) { if (!ModelState.IsValid) { return(BadRequest()); } //save it and respond _localizedPropertyService.Insert(model); VerboseReporter.ReportSuccess("Thêm ngôn ngữ thành công", "post"); return(RespondSuccess(model)); }
public IActionResult Delete(int id) { if (id <= 0) { return(BadRequest()); } var emailMessage = _emailService.FirstOrDefault(x => x.Id == id); _emailService.Delete(emailMessage); VerboseReporter.ReportSuccess("Xóa EmailMessage thành công", "delete"); return(RespondSuccess()); }
protected virtual void SaveLocalizedValue(Menu service, MenuModel entityModel) { if (entityModel.LanguageId <= 0) { return; } _localizedPropertyService.SaveLocalizedValue(service, x => x.Name, entityModel.Name, entityModel.LanguageId); VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "put"); }
public IHttpActionResult Post(ThirdPartySettingsModel entityModel) { var thirdPartySettings = new ThirdPartySettings() { EchonestApiKey = entityModel.EchonestApiKey, SevenDigitalOAuthConsumerKey = entityModel.SevenDigitalOAuthConsumerKey, SevenDigitalOAuthConsumerSecret = entityModel.SevenDigitalOAuthConsumerSecret, SevenDigitalPartnerId = entityModel.SevenDigitalPartnerId }; _settingService.Save(thirdPartySettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { ThirdPartySettings = thirdPartySettings.ToModel() })); }
public IActionResult Delete(int id) { if (id <= 0) { return(BadRequest()); } var localizedProperty = _localizedPropertyService.FirstOrDefault(x => x.Id == id); _localizedPropertyService.Delete(localizedProperty); VerboseReporter.ReportSuccess("Xóa ngôn ngữ thành công", "delete"); return(RespondSuccess()); }
//[Authorize] public IActionResult Post([FromBody] CategoryPostModel entityModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var category = entityModel.ToEntity(); //save it _categoryService.Insert(category); VerboseReporter.ReportSuccess("Tạo danh mục thành công", "post"); return(RespondSuccess(entityModel)); }
public IActionResult Post(EmailMessage model) { if (!ModelState.IsValid) { return(BadRequest()); } var emailMessage = model;//.ToEntity(); //save it and respond _emailService.Insert(emailMessage); VerboseReporter.ReportSuccess("Thêm EmailMessage thành công", "post"); return(RespondSuccess(emailMessage)); }
public IActionResult Put(LocaleStringResource entityModel) { var localeStringResource = _localeStringResourceService.FirstOrDefault(x => x.Id == entityModel.Id); //save it and respond localeStringResource.ResourceName = entityModel.ResourceName; localeStringResource.ResourceValue = entityModel.ResourceValue; localeStringResource.LanguageId = entityModel.LanguageId; _localeStringResourceService.Update(localeStringResource); VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "post"); return(RespondSuccess(localeStringResource)); }
public IHttpActionResult Post(BattleSettingsModel entityModel) { var battleSettings = new BattleSettings() { BattleHostPictureBattleSponsorshipPercentage = entityModel.BattleHostPictureBattleSponsorshipPercentage, BattleHostVideoBattleSponsorshipPercentage = entityModel.BattleHostVideoBattleSponsorshipPercentage, DefaultVideosFeaturedImageUrl = entityModel.DefaultVideosFeaturedImageUrl, DefaultVotingChargeForPaidVoting = entityModel.DefaultVotingChargeForPaidVoting, SiteOwnerPictureBattleSponsorshipPercentage = entityModel.SiteOwnerPictureBattleSponsorshipPercentage, SiteOwnerVideoBattleSponsorshipPercentage = entityModel.SiteOwnerVideoBattleSponsorshipPercentage }; _settingService.Save(battleSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { BattleSettings = battleSettings.ToModel() })); }
public IActionResult Put(LocalizedProperty entityModel) { var localizedProperty = _localizedPropertyService.FirstOrDefault(x => x.Id == entityModel.Id); //save it and respond localizedProperty.LocaleKey = entityModel.LocaleKey; localizedProperty.LocaleValue = entityModel.LocaleValue; localizedProperty.LanguageId = entityModel.LanguageId; _localizedPropertyService.Update(localizedProperty); VerboseReporter.ReportSuccess("Sửa ngôn ngữ thành công", "post"); return(RespondSuccess(localizedProperty)); }
public async Task <IActionResult> Get([FromRoute] string seName) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var page = await _categoryService.GetBySeNameAsync(seName); if (page == null) { VerboseReporter.ReportError("Không tìm thấy danh mục"); return(RespondFailure()); } var model = page.ToModel(); return(RespondSuccess(model)); }
public IActionResult Post(MenuModel entityModel) { //if (!ModelState.IsValid) // return BadRequest(); var menu = entityModel.ToEntity(); menu.CreatedBy = CurrentUser.Id; //save it _menuService.Insert(menu); var model = menu.ToModel(); SaveLocalizedValue(menu, model); VerboseReporter.ReportSuccess("Tạo Menu thành công", "post"); return(RespondSuccess(model)); }
public IHttpActionResult Post(GeneralSettingsModel entityModel) { var generalSettings = new GeneralSettings() { ApplicationApiRoot = entityModel.ApplicationApiRoot, ApplicationCookieDomain = entityModel.ApplicationCookieDomain, ApplicationUiDomain = entityModel.ApplicationUiDomain, VideoServerDomain = entityModel.VideoServerDomain, ImageServerDomain = entityModel.ImageServerDomain, DefaultTimeZoneId = entityModel.DefaultTimeZoneId }; //save it and respond _settingService.Save(generalSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { GeneralSettings = generalSettings.ToModel() })); }
public IHttpActionResult Put(EmailAccountEntityModel entityModel) { if (!ModelState.IsValid) { return(BadRequest()); } //get the account var emailAccount = _emailAccountService.Get(entityModel.Id); if (emailAccount == null) { return(NotFound()); } emailAccount.FromName = entityModel.FromName; emailAccount.Host = entityModel.Host; emailAccount.IsDefault = entityModel.IsDefault; emailAccount.Port = entityModel.Port; emailAccount.UseDefaultCredentials = entityModel.UseDefaultCredentials; emailAccount.UseSsl = entityModel.UseSsl; emailAccount.UserName = entityModel.UserName; emailAccount.Email = entityModel.Email; //we'll change password if it's provided if (!string.IsNullOrEmpty(entityModel.Password)) { emailAccount.Password = _cryptographyService.Encrypt(entityModel.Password); } //save it _emailAccountService.Update(emailAccount); //if this is a default account now, update the previous one if (emailAccount.IsDefault) { var oldDefaultEmailAccount = _emailAccountService.FirstOrDefault(x => x.IsDefault && x.Id != emailAccount.Id); if (oldDefaultEmailAccount != null) { oldDefaultEmailAccount.IsDefault = false; _emailAccountService.Update(emailAccount); } } VerboseReporter.ReportSuccess("Successfully updated email account", "put_emailaccount"); return(RespondSuccess(new { EmailAccount = emailAccount.ToEntityModel() })); }
public IHttpActionResult Install(PluginInfoModel model) { //first find the plugin var pluginInfo = _pluginFinderService.FindPlugin(model.SystemName); if (pluginInfo == null) { //was it a correct plugin? VerboseReporter.ReportError("The plugin doesn't exist", "plugin"); return(RespondFailure()); } //install the plugin _pluginInstallerService.Install(pluginInfo); VerboseReporter.ReportSuccess("The plugin has been installed", "plugin"); return(RespondSuccess()); }
public IHttpActionResult Post(PaymentSettingsModel entityModel) { var paymentSettings = new PaymentSettings() { CreditExchangeRate = entityModel.CreditExchangeRate, IsPromotionalCreditUsageLimitPercentage = entityModel.IsPromotionalCreditUsageLimitPercentage, MacroPaymentsFixedPaymentProcessingFee = entityModel.MacroPaymentsFixedPaymentProcessingFee, MacroPaymentsPaymentProcessingPercentage = entityModel.MacroPaymentsPaymentProcessingPercentage, MicroPaymentsFixedPaymentProcessingFee = entityModel.MicroPaymentsFixedPaymentProcessingFee, MicroPaymentsPaymentProcessingPercentage = entityModel.MicroPaymentsPaymentProcessingPercentage, PaymentMethodSelectionType = entityModel.PaymentMethodSelectionType, PromotionalCreditUsageLimitPerTransaction = entityModel.PromotionalCreditUsageLimitPerTransaction }; _settingService.Save(paymentSettings); VerboseReporter.ReportSuccess("Settings saved successfully", "post_setting"); return(RespondSuccess(new { PaymentSettings = paymentSettings.ToModel() })); }