update UI.
This commit is contained in:
parent
dd1bc2d8aa
commit
c546a14aa1
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
|
||||
<PackageReference Include="Senparc.Weixin.MP.MVC" Version="7.2.5" />
|
||||
<PackageReference Include="Senparc.Weixin.MP.MVC" Version="7.2.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
87
BotSharp.Core/Accounts/AccountController.cs
Normal file
87
BotSharp.Core/Accounts/AccountController.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using DotNetToolkit.JwtHelper;
|
||||
using DotNetToolkit;
|
||||
using EntityFrameworkCore.BootKit;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace BotSharp.Core.Accounts
|
||||
{
|
||||
/// <summary>
|
||||
/// The /account endpoint is used to create, retrieve, update, and delete account.
|
||||
/// </summary>
|
||||
public class AccountController : CoreController
|
||||
{
|
||||
private IConfiguration config;
|
||||
|
||||
public AccountController(IConfiguration config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
[HttpGet("/account")]
|
||||
public VmUser GetUser()
|
||||
{
|
||||
/*var user = dc.Table<User>().Find(CurrentUserId);
|
||||
return user.ToObject<VmUser>();*/
|
||||
return new VmUser
|
||||
{
|
||||
Email = "botsharp@ai.com",
|
||||
FirstName = "Bot",
|
||||
LastName = "Sharp"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a valid token after login
|
||||
/// </summary>
|
||||
/// <param name="username">User Email</param>
|
||||
/// <param name="password">Password</param>
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("/token")]
|
||||
[ProducesResponseType(typeof(string), 200)]
|
||||
public IActionResult Token([FromBody] VmUserLogin userModel)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userModel.UserName) || string.IsNullOrEmpty(userModel.Password))
|
||||
{
|
||||
return new BadRequestObjectResult("Username and password should not be empty.");
|
||||
}
|
||||
return Ok(JwtToken.GenerateToken(config, "botsharp"));
|
||||
// validate from local
|
||||
var user = (from usr in dc.Table<User>()
|
||||
join auth in dc.Table<UserAuth>() on usr.Id equals auth.UserId
|
||||
where usr.UserName == userModel.UserName
|
||||
select auth).FirstOrDefault();
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
if (!user.IsActivated)
|
||||
{
|
||||
return BadRequest("Account hasn't been activated, please check your email to activate it.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// validate password
|
||||
string hash = PasswordHelper.Hash(userModel.Password, user.Salt);
|
||||
if (user.Password == hash)
|
||||
{
|
||||
return Ok(JwtToken.GenerateToken(config, "botsharp"));
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("Authorization Failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest("Account doesn't exist");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,21 +15,21 @@ namespace BotSharp.Core.Accounts
|
|||
{
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
public String UserName { get; set; }
|
||||
public string UserName { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
[DataType(DataType.EmailAddress)]
|
||||
public String Email { get; set; }
|
||||
public string Email { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public String FirstName { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public String LastName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
|
||||
[MaxLength(256)]
|
||||
public String Description { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.DateTime)]
|
||||
|
|
@ -39,14 +39,14 @@ namespace BotSharp.Core.Accounts
|
|||
public DateTime? Birthday { get; set; }
|
||||
|
||||
[MaxLength(36)]
|
||||
public String Nationality { get; set; }
|
||||
public string Nationality { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public String FullName
|
||||
public string FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
return FirstName + (String.IsNullOrEmpty(LastName) ? "" : " " + LastName);
|
||||
return FirstName + (string.IsNullOrEmpty(LastName) ? "" : " " + LastName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,21 +14,21 @@ namespace BotSharp.Core.Accounts
|
|||
public class UserAuth : DbRecord, IDbRecord
|
||||
{
|
||||
[StringLength(36)]
|
||||
public String UserId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(256)]
|
||||
[DataType(DataType.Password)]
|
||||
public String Password { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(64)]
|
||||
public String Salt { get; set; }
|
||||
public string Salt { get; set; }
|
||||
|
||||
[StringLength(32)]
|
||||
public String ActivationCode { get; set; }
|
||||
public string ActivationCode { get; set; }
|
||||
|
||||
public Boolean IsActivated { get; set; }
|
||||
public bool IsActivated { get; set; }
|
||||
|
||||
[ForeignKey("UserId")]
|
||||
public User User { get; set; }
|
||||
|
|
|
|||
21
BotSharp.Core/Accounts/VmUser.cs
Normal file
21
BotSharp.Core/Accounts/VmUser.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Core.Accounts
|
||||
{
|
||||
public class VmUser
|
||||
{
|
||||
public String FullName
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"{FirstName} {LastName}";
|
||||
}
|
||||
}
|
||||
public String FirstName { get; set; }
|
||||
public String LastName { get; set; }
|
||||
public String Email { get; set; }
|
||||
public String Avatar { get; set; }
|
||||
}
|
||||
}
|
||||
13
BotSharp.Core/Accounts/VmUserLogin.cs
Normal file
13
BotSharp.Core/Accounts/VmUserLogin.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Core.Accounts
|
||||
{
|
||||
public class VmUserLogin
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -74,15 +74,16 @@ If you feel that this project is helpful to you, please Star on the project, we
|
|||
<ItemGroup>
|
||||
<PackageReference Include="CherubNLP" Version="0.2.0" />
|
||||
<PackageReference Include="Colorful.Console" Version="1.2.9" />
|
||||
<PackageReference Include="CSRedisCore" Version="3.0.40" />
|
||||
<PackageReference Include="DotNetToolkit" Version="1.6.0" />
|
||||
<PackageReference Include="CSRedisCore" Version="3.0.41" />
|
||||
<PackageReference Include="DotNetToolkit" Version="1.7.0" />
|
||||
<PackageReference Include="EntityFrameworkCore.BootKit" Version="1.11.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="NumSharp" Version="0.7.3" />
|
||||
<PackageReference Include="NumSharp" Version="0.7.4" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
<PackageReference Include="TensorFlow.NET" Version="0.4.1" />
|
||||
<PackageReference Include="TensorFlow.NET" Version="0.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
43
BotSharp.Core/CoreController.cs
Normal file
43
BotSharp.Core/CoreController.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
using EntityFrameworkCore.BootKit;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BotSharp.Core
|
||||
{
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("v1/[controller]")]
|
||||
public class CoreController : ControllerBase
|
||||
{
|
||||
protected Database dc { get; set; }
|
||||
|
||||
public CoreController()
|
||||
{
|
||||
dc = new DefaultDataContextLoader().GetDefaultDc();
|
||||
}
|
||||
|
||||
/*protected string GetConfig(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) return String.Empty;
|
||||
|
||||
return Database.Configuration.GetSection(path).Value;
|
||||
}
|
||||
|
||||
protected List<KeyValuePair<string, string>> GetSection(string path)
|
||||
{
|
||||
return Database.Configuration.GetSection(path).AsEnumerable().ToList();
|
||||
}*/
|
||||
|
||||
protected string CurrentUserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ BotSharp Web Console
|
|||
## How to install
|
||||
#### Download source code
|
||||
````sh
|
||||
git clone https://github.com/Oceania2018/BotSharp
|
||||
git clone https://github.com/SciSharp/BotSharp
|
||||
````
|
||||
#### Run node.js server
|
||||
````sh
|
||||
|
|
|
|||
1159
BotSharp.UI/package-lock.json
generated
1159
BotSharp.UI/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -17,8 +17,8 @@
|
|||
"dependencies": {
|
||||
"axios": "^0.16.2",
|
||||
"iview": "^2.14.3",
|
||||
"localStorage": "^1.0.3",
|
||||
"vue": "^2.5.17",
|
||||
"localStorage": "^1.0.4",
|
||||
"vue": "^2.6.8",
|
||||
"vue-avatar-editor": "^1.0.4",
|
||||
"vue-input-tag": "0.0.16",
|
||||
"vue-localstorage": "^0.3.0",
|
||||
|
|
@ -47,9 +47,9 @@
|
|||
"vue-html-loader": "^1.2.3",
|
||||
"vue-loader": "^11.0.0",
|
||||
"vue-style-loader": "^1.0.0",
|
||||
"vue-template-compiler": "^2.5.17",
|
||||
"vue-template-compiler": "^2.6.8",
|
||||
"webpack": "^2.2.1",
|
||||
"webpack-dev-server": "^2.11.2",
|
||||
"webpack-dev-server": "^2.11.3",
|
||||
"webpack-merge": "^3.0.0"
|
||||
},
|
||||
"bugs": {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetToolkit" Version="1.6.0" />
|
||||
<PackageReference Include="DotNetToolkit" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
|
||||
|
|
|
|||
|
|
@ -29,7 +29,16 @@ namespace BotSharp.WebHost
|
|||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddCors();
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAllHeaders", builder =>
|
||||
{
|
||||
builder.WithOrigins("http://localhost:3110")
|
||||
.AllowCredentials()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
services.AddJwtAuth(Configuration);
|
||||
|
||||
var mvcBuilder = services.AddMvc(options =>
|
||||
|
|
@ -82,7 +91,7 @@ namespace BotSharp.WebHost
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
|
||||
app.UseCors("AllowAllHeaders");
|
||||
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
|
|
|
|||
Loading…
Reference in a new issue