Skip to content

Commit

Permalink
[Add] 补传误删额backend.Core.
Browse files Browse the repository at this point in the history
  • Loading branch information
undefinedHR committed Apr 24, 2019
1 parent 4ab692e commit 64bc861
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/backend/backend.Api/obj
/backend/backend.Web/bin/Debug/netcoreapp2.1
/backend/backend.Web/obj
/backend/backend.Core/bin/Debug/netcoreapp2.1
/backend/backend.Core/obj
6 changes: 6 additions & 0 deletions backend/backend.Api/Controllers/AuthrorizeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace backend.Api.Controllers
{
Expand Down Expand Up @@ -47,6 +48,9 @@ public IActionResult Login([FromBody]LoginViewModel model)
{
var user = _db.Users.SingleOrDefault(c => c.UserName == model.UserName);

if (user == null)
return Json(ReturnJson.NotFound("该用户不存在"));

if (user.Password != Crypto.DesEncrypt(model.Password))
return Json(ReturnJson.ServerError("用户名密码错误"));

Expand Down Expand Up @@ -76,7 +80,9 @@ public IActionResult Register([FromBody]RegisterViewModel model)
UserName = model.UserName,
NickName = model.NickName,
Phone = model.Phone,
IsVerifyPhone = CustomerEnum.Verification.False,
Email = model.Email,
IsVerifyEmail = CustomerEnum.Verification.False,
Password = Crypto.DesEncrypt(model.Password),
UserRole = CustomerEnum.UserRole.Admin
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions backend/backend.Api/Migrations/20190424013234_CreateUserTable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace backend.Api.Migrations
{
public partial class CreateUserTable : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "user",
columns: table => new
{
id = table.Column<Guid>(nullable: false),
user_name = table.Column<string>(maxLength: 64, nullable: true),
nick_name = table.Column<string>(maxLength: 64, nullable: true),
phone = table.Column<string>(maxLength: 64, nullable: true),
email = table.Column<string>(maxLength: 64, nullable: true),
is_verify_phone = table.Column<int>(nullable: false),
is_verify_email = table.Column<int>(nullable: false),
password = table.Column<string>(maxLength: 64, nullable: true),
user_role = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_user", x => x.id);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "user");
}
}
}
62 changes: 62 additions & 0 deletions backend/backend.Api/Migrations/MyContextModelSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using backend.Api.Data;

namespace backend.Api.Migrations
{
[DbContext(typeof(MyContext))]
partial class MyContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.1.8-servicing-32085")
.HasAnnotation("Relational:MaxIdentifierLength", 64);

modelBuilder.Entity("backend.Core.Entities.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id");

b.Property<string>("Email")
.HasColumnName("email")
.HasMaxLength(64);

b.Property<int>("IsVerifyEmail")
.HasColumnName("is_verify_email");

b.Property<int>("IsVerifyPhone")
.HasColumnName("is_verify_phone");

b.Property<string>("NickName")
.HasColumnName("nick_name")
.HasMaxLength(64);

b.Property<string>("Password")
.HasColumnName("password")
.HasMaxLength(64);

b.Property<string>("Phone")
.HasColumnName("phone")
.HasMaxLength(64);

b.Property<string>("UserName")
.HasColumnName("user_name")
.HasMaxLength(64);

b.Property<int>("UserRole")
.HasColumnName("user_role");

b.HasKey("Id");

b.ToTable("user");
});
#pragma warning restore 612, 618
}
}
}
2 changes: 1 addition & 1 deletion backend/backend.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"default": "server=119.23.34.239;port=3306;database=mps;uid=root;password=root;Charset=uft8"
"default": "server=119.23.34.239;port=3306;database=mps2019;uid=root;password=root;Charset=uft8"
},
"Logging": {
"LogLevel": {
Expand Down
2 changes: 1 addition & 1 deletion backend/backend.Api/backend.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ClassLibrary3\backend.Core.csproj" />
<ProjectReference Include="..\backend.Core\backend.Core.csproj" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions backend/backend.Core/Customers/CustomerEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace backend.Core.Customers
{
public class CustomerEnum
{
public enum UserRole
{
Admin = 1,
User = 11
}

public enum HttpCode
{
Success = 200,
NotFound = 404,
Forbidden = 403,
ServerError = 500
}

public enum Verification
{
True = 1,
False = 0
}
}
}
13 changes: 13 additions & 0 deletions backend/backend.Core/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace backend.Core.Entities
{
public abstract class Entity
{
[Column("id")]
public Guid Id { get; set; }
}
}
30 changes: 30 additions & 0 deletions backend/backend.Core/Entities/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using backend.Core.Customers;

namespace backend.Core.Entities
{
[Table("user")]
public class User: Entity
{
[Column("user_name"), MaxLength(64)]
public string UserName { get; set; }
[Column("nick_name"), MaxLength(64)]
public string NickName { get; set; }
[Column("phone"), MaxLength(64)]
public string Phone { get; set; }
[Column("email"), MaxLength(64)]
public string Email { get; set; }
[Column("is_verify_phone")]
public CustomerEnum.Verification IsVerifyPhone { get; set; }
[Column("is_verify_email")]
public CustomerEnum.Verification IsVerifyEmail { get; set; }
[Column("password"), MaxLength(64)]
public string Password { get; set; }
[Column("user_role")]
public CustomerEnum.UserRole UserRole { get; set; }
}
}
37 changes: 37 additions & 0 deletions backend/backend.Core/Helper/Crypto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace backend.Core.Helper
{
public class Crypto
{
public static readonly string Key = "MPSRenew";
public static DESCryptoServiceProvider DesCsp = new DESCryptoServiceProvider();

public static string DesEncrypt(string value)
{
var buffer = Encoding.UTF8.GetBytes(value);
var ms = new MemoryStream();
var encStream = new CryptoStream(ms, DesCsp.CreateEncryptor(Encoding.UTF8.GetBytes(Key), Encoding.UTF8.GetBytes(Key)), CryptoStreamMode.Write);
encStream.Write(buffer, 0, buffer.Length);
encStream.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray()).Replace("+", "%");
}

public static string DesDecrypt(string value)
{
value = value.Replace("%", "+");
var buffer = Convert.FromBase64String(value);
var ms = new MemoryStream();
var decStream = new CryptoStream(ms,
DesCsp.CreateDecryptor(Encoding.UTF8.GetBytes(Key), Encoding.UTF8.GetBytes(Key)),
CryptoStreamMode.Read);
decStream.Write(buffer, 0, buffer.Length);
decStream.FlushFinalBlock();
return Encoding.UTF8.GetString(ms.ToArray());
}
}
}
64 changes: 64 additions & 0 deletions backend/backend.Core/Helper/ReturnJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Text;
using backend.Core.Customers;
using Newtonsoft.Json;

namespace backend.Core.Helper
{
public static class ReturnJson
{
public class Return
{
[JsonProperty("code")]
public CustomerEnum.HttpCode Code { get; set; }
[JsonProperty("data")]
public object Data { get; set; }
}

public static Return Success(object data = null)
{
var model = new Return
{
Code = CustomerEnum.HttpCode.Success,
Data = data
};

return model;
}


public static Return NotFound(object data = null)
{
var model = new Return
{
Code = CustomerEnum.HttpCode.NotFound,
Data = data
};

return model;
}

public static Return ServerError(object data = null)
{
var model = new Return
{
Code = CustomerEnum.HttpCode.ServerError,
Data = data
};

return model;
}

public static Return Forbidden(object data = null)
{
var model = new Return
{
Code = CustomerEnum.HttpCode.Forbidden,
Data = data
};

return model;
}
}
}
Loading

0 comments on commit 64bc861

Please sign in to comment.