Skip to content

Commit

Permalink
Merge pull request #160 from mixcore/develop
Browse files Browse the repository at this point in the history
Merge latest Develop branch to Master
  • Loading branch information
Smilefounder authored Dec 23, 2019
2 parents ca34da1 + b1068f8 commit f491acd
Show file tree
Hide file tree
Showing 787 changed files with 48,436 additions and 23,552 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,10 @@ src/Mix\.Cms\.Web/Cache/
.DS_Store

.vscode/

src/Mix.Cms.Web/appsettings.*.json
/src/_MixCore.sln

src/Mix.Cms.Web/logs/

src/Mix.Cms.Web.old/
Binary file added assets/crm-flow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions src/Mix.Cms.Api/Controllers/v1/ApiAccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public async Task<RepositoryResponse<AccessTokenViewModel>> RefreshToken(string
[Route("Register")]
[HttpPost, HttpOptions]
[AllowAnonymous]
public async Task<RepositoryResponse<AccessTokenViewModel>> Register([FromBody] MixRegisterViewModel model)
public async Task<ActionResult<RepositoryResponse<AccessTokenViewModel>>> Register([FromBody] MixRegisterViewModel model)
{
RepositoryResponse<AccessTokenViewModel> result = new RepositoryResponse<AccessTokenViewModel>();
if (ModelState.IsValid)
Expand All @@ -180,16 +180,15 @@ public async Task<RepositoryResponse<AccessTokenViewModel>> Register([FromBody]
Avatar = model.Avatar ?? MixService.GetConfig<string>("DefaultAvatar"),
JoinDate = DateTime.UtcNow
};

var createResult = await _userManager.CreateAsync(user, password: model.Password).ConfigureAwait(false);
if (createResult.Succeeded)
{
_logger.LogInformation("User created a new account with password.");

user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);
model.Id = user.Id;
model.CreatedDateTime = DateTime.UtcNow;
// Save to cms db context

await model.SaveModelAsync();
var token = await _helper.GenerateAccessTokenAsync(user, true);
if (token != null)
Expand All @@ -201,7 +200,7 @@ public async Task<RepositoryResponse<AccessTokenViewModel>> Register([FromBody]
}
else
{
return result;
return Ok(result);
}
}
else
Expand All @@ -210,11 +209,11 @@ public async Task<RepositoryResponse<AccessTokenViewModel>> Register([FromBody]
{
result.Errors.Add(error.Description);
}
return result;
return BadRequest(result);
}
}

return result;
return BadRequest(result);
}

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme,
Expand Down
23 changes: 9 additions & 14 deletions src/Mix.Cms.Api/Controllers/v1/ApiFileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The Mixcore Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Mix.Cms.Lib.Models.Cms;
Expand Down Expand Up @@ -45,15 +46,11 @@ public RepositoryResponse<FileViewModel> Details(string folder, string filename)

// GET api/files/id
[HttpGet, HttpOptions]
[Route("delete/{id}")]
public RepositoryResponse<bool> Delete(RequestObject request)
[Route("delete")]
public RepositoryResponse<bool> Delete()
{
string fullPath = CommonHelper.GetFullPath(new string[]
{
request.Key,
request.Keyword
});
var result = FileRepository.Instance.DeleteWebFile(fullPath);
string fullPath = Request.Query["fullPath"].ToString();
var result = FileRepository.Instance.DeleteFile(fullPath);
return new RepositoryResponse<bool>()
{
IsSucceed = result,
Expand All @@ -65,16 +62,16 @@ public RepositoryResponse<bool> Delete(RequestObject request)
/// <summary>
/// Uploads the image.
/// </summary>
/// <param name="image">The img information.</param>
/// <param name="image">The img information.</param>
/// <param name="file"></param> Ex: { "base64": "", "fileFolder":"" }
/// <returns></returns>
[Route("uploadFile")]
[Route("upload-file")]
[HttpPost, HttpOptions]
public IActionResult Edit(FileViewModel file)
public IActionResult Upload([FromForm] string folder, [FromForm]IFormFile file)
{
if (ModelState.IsValid)
{
var result = FileRepository.Instance.SaveWebFile(file);
var result = FileRepository.Instance.SaveFile(file, file.FileName, folder);
return Ok(result);
}
return BadRequest();
Expand Down Expand Up @@ -117,7 +114,5 @@ public RepositoryResponse<FilePageViewModel> GetList([FromBody]RequestPaging req
};
}
#endregion Post


}
}
11 changes: 8 additions & 3 deletions src/Mix.Cms.Api/Controllers/v1/ApiInitCmsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ public async Task<RepositoryResponse<AccessTokenViewModel>> InitSuperAdmin([From
if (createResult.Succeeded)
{
user = await _userManager.FindByEmailAsync(model.Email).ConfigureAwait(false);
await _userManager.AddToRoleAsync(user, "SuperAdmin");
model.ExpandView();
model.Id = user.Id;
model.CreatedDateTime = DateTime.UtcNow;
model.Avatar = model.Avatar ?? MixService.GetConfig<string>("DefaultAvatar");
// Save to cms db context

await model.SaveModelAsync();
await _userManager.AddToRoleAsync(user, "SuperAdmin");

var token = await _idHelper.GenerateAccessTokenAsync(user, true);
if (token != null)
{
Expand Down Expand Up @@ -209,6 +211,7 @@ public async Task<RepositoryResponse<bool>> InitLanguages([FromBody]List<MixLang
MixService.SetConfig("InitStatus", 4);
MixService.SetConfig("IsInit", true);
MixService.SaveSettings();
_ = MixCacheService.RemoveCacheAsync();
MixService.Reload();
}
}
Expand All @@ -235,7 +238,7 @@ public async Task<RepositoryResponse<bool>> InitLanguages([FromBody]List<MixLang
if (theme != null)
{
string importFolder = $"Imports/Themes/{DateTime.UtcNow.ToString("dd-MM-yyyy")}/{data.Name}";
FileRepository.Instance.SaveWebFile(theme, importFolder);
FileRepository.Instance.SaveWebFile(theme, theme.FileName, importFolder);
data.TemplateAsset = new Lib.ViewModels.FileViewModel(theme, importFolder);
}
else
Expand Down Expand Up @@ -273,7 +276,9 @@ public async Task<RepositoryResponse<bool>> InitLanguages([FromBody]List<MixLang
// MixService.SetConfig<string>("SiteName", _lang, data.Title);
MixService.LoadFromDatabase();
MixService.SetConfig("InitStatus", 3);
MixService.SetConfig("IsInit", true);
MixService.SaveSettings();
_ = MixCacheService.RemoveCacheAsync();
MixService.Reload();
}
return result;
Expand Down Expand Up @@ -304,7 +309,7 @@ private async Task<RepositoryResponse<bool>> InitStep1Async(InitCmsViewModel mod
MixService.SetConfig<string>("DefaultCulture", model.Culture.Specificulture);
MixService.SetConfig("InitStatus", 1);
MixService.SaveSettings();
MixService.Reload();
//MixService.Reload();
}
else
{
Expand Down
10 changes: 6 additions & 4 deletions src/Mix.Cms.Api/Controllers/v1/ApiMediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ public async Task<ActionResult<JObject>> Details(string viewType, int? id)
#region Post

// POST api/media
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "SuperAdmin, Admin")]
[HttpPost, HttpOptions]
[Route("save")]
public async Task<RepositoryResponse<UpdateViewModel>> Save([FromBody]UpdateViewModel model)
public async Task<RepositoryResponse<UpdateViewModel>> Save([FromForm]string model, [FromForm]IFormFile file)
{
if (model != null)
{
model.Specificulture = _lang;
var result = await base.SaveAsync<UpdateViewModel>(model, true);
var json = JObject.Parse(model);
var data = json.ToObject<UpdateViewModel>();
data.Specificulture = _lang;
data.File = file;
var result = await base.SaveAsync<UpdateViewModel>(data, true);
return result;
}
return new RepositoryResponse<UpdateViewModel>() { Status = 501 };
Expand Down
19 changes: 19 additions & 0 deletions src/Mix.Cms.Api/Controllers/v1/ApiModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Mix.Cms.Lib;
using Mix.Cms.Lib.Models.Cms;
using Mix.Cms.Lib.Services;
using Mix.Cms.Lib.ViewModels;
Expand Down Expand Up @@ -143,6 +144,24 @@ public async Task<RepositoryResponse<MixModule>> SaveFields(int id, [FromBody]Li
return new RepositoryResponse<MixModule>();
}

// POST api/module
[HttpPost, HttpOptions]
[Route("data/save/{name}/{formName}")]
public async Task<ActionResult<JObject>> SaveData(string name, string formName, [FromBody]JObject obj)
{
// Get module by name
string _username = User?.Claims.FirstOrDefault(c => c.Type == "Username")?.Value;
var result = await ODataMobileViewModel.SaveByModuleName(_lang, _username, name, formName, obj);
if (result.IsSucceed)
{
return Ok(result);
}
else
{
return BadRequest(result);
}
}

// GET api/module
[HttpPost, HttpOptions]
[Route("list")]
Expand Down
3 changes: 3 additions & 0 deletions src/Mix.Cms.Api/Controllers/v1/ApiModuleDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public async Task<ActionResult<RepositoryResponse<PaginationModel<ReadViewModel>
Expression<Func<MixModuleData, bool>> predicate = model =>
model.Specificulture == _lang
&& model.ModuleId == moduleId
&& (string.IsNullOrEmpty(request.Keyword) || model.Value.Contains(request.Keyword))
&& (postId == 0 || model.PostId == postId)
&& (pageId == 0 || model.PageId == pageId)
&& (!request.FromDate.HasValue
Expand Down Expand Up @@ -288,10 +289,12 @@ public async Task<ActionResult<RepositoryResponse<PaginationModel<ReadViewModel>
int.TryParse(query.Get("post_id"), out int postId);
int.TryParse(query.Get("product_id"), out int productId);
int.TryParse(query.Get("category_id"), out int pageId);

string key = $"{request.Key}_{request.PageSize}_{request.PageIndex}";
Expression<Func<MixModuleData, bool>> predicate = model =>
model.Specificulture == _lang
&& model.ModuleId == moduleId
&& (string.IsNullOrEmpty(request.Keyword) || model.Value.Contains(request.Keyword))
&& (postId == 0 || model.PostId == postId)
&& (pageId == 0 || model.PageId == pageId)
&& (!request.FromDate.HasValue
Expand Down
Loading

0 comments on commit f491acd

Please sign in to comment.