新增用户注册功能

This commit is contained in:
Argo-Lenovo 2016-11-06 16:01:14 +08:00
parent df2cb74fd7
commit fd96c9d420
11 changed files with 319 additions and 18 deletions

View File

@ -113,6 +113,7 @@
<Content Include="Content\css\font-awesome.min.css" />
<Content Include="Content\css\jquery.nestable.css" />
<Content Include="Content\css\lock.css" />
<Content Include="Content\css\register.css" />
<Content Include="Content\css\tasks.css" />
<Content Include="Content\images\bg.jpg" />
<Content Include="Content\images\lock-bg.jpg" />
@ -169,6 +170,7 @@
<Content Include="Scripts\Logs.js" />
<Content Include="Scripts\Menus.js" />
<Content Include="Scripts\Profiles.js" />
<Content Include="Scripts\register.js" />
<Content Include="Scripts\Roles.js" />
<Content Include="Scripts\Users.js" />
<Content Include="Content\js\jquery-1.10.2.js" />
@ -257,6 +259,7 @@
<Content Include="Views\Shared\SubMenu.cshtml" />
<Content Include="Views\Shared\SubMenuTree.cshtml" />
<Content Include="Views\Home\Lock.cshtml" />
<Content Include="Views\Home\Register.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

@ -0,0 +1,136 @@
ol {
display: block;
list-style-type: decimal;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
.setup-wrapper {
width: 750px;
padding-top: 30px;
margin: 0 auto;
}
.setup-header {
padding-bottom: 20px;
margin: 0 auto 30px;
overflow: hidden;
text-align: left;
}
.setup-confirm {
display: none;
}
.setup-confirm h4 {
padding: 6px 0;
}
.setup-confirm div {
padding-top: 30px;
}
.setup-confirm button {
margin-top: 30px;
}
.setup-main, .setup-confirm {
float: left;
width: 450px;
}
.setup-main span {
top: 0;
}
.setup-main .input-group {
margin-bottom: 15px;
}
.setup-secondary {
float: right;
width: 250px;
}
.setup-info-module {
margin-bottom: 30px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 3px;
box-shadow: 0 1px 3px rgba(0,0,0,0.075);
}
.setup-info-module h4 {
padding: 15px;
margin-bottom: 15px;
overflow: hidden;
border-bottom: 1px solid #ddd;
margin-top: 0;
}
.features-list {
padding: 0 15px 15px;
margin: 0;
font-size: 14px;
list-style: none;
}
.features-list li:first-child {
margin-top: 0;
}
.features-list li {
margin-top: 10px;
}
.features-list li strong {
font-weight: 600;
}
.features-list li i {
margin-right: 5px;
color: #60b044;
}
.features-list .list-divider {
margin: 15px -15px;
border-top: 1px solid #eee;
}
.steps {
display: table;
width: 100%;
padding: 0;
margin: 30px auto 0;
overflow: hidden;
list-style: none;
border: 1px solid #ddd;
border-radius: 3px;
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.steps li:first-child {
border-left: 0;
}
.steps li.current {
color: #333;
background-color: #fff;
}
.steps li {
display: table-cell;
width: 33.3%;
padding: 10px 15px;
color: #ccc;
cursor: default;
background-color: #fafafa;
border-left: 1px solid #ddd;
}
.steps li .step {
display: block;
}

View File

@ -67,5 +67,16 @@ namespace Bootstrap.Admin.Controllers
FormsAuthentication.SignOut();
return RedirectToAction("Login");
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[AllowAnonymous]
public ActionResult Register(string userName, string displayName, string password)
{
var result = UserHelper.RegisterUser(userName, displayName, password);
if (result) return RedirectToAction("Login");
else return View();
}
}
}

View File

@ -1,6 +1,7 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
@ -64,6 +65,7 @@ namespace Bootstrap.Admin.Controllers
[HttpPost]
public bool Post([FromBody]User value)
{
value.ApprovedTime = DateTime.Now;
return UserHelper.SaveUser(value);
}

View File

@ -0,0 +1,27 @@
$(function () {
$('form').autoValidate({
userName: {
required: true,
maxlength: 50
},
displayName: {
required: true,
maxlength: 50
},
password: {
required: true,
maxlength: 50
}
});
$('#btnAccount').click(function () {
var valid = $('form').valid();
if (valid) {
$('.setup-main').hide();
$('.steps li').toggleClass('current');
$('.setup-confirm span:first').text($('#userName').val());
$('.setup-confirm span:last').text($('#displayName').val());
$('.setup-confirm').show();
}
});
});

View File

@ -0,0 +1,74 @@
@{
ViewBag.Title = "注册新用户";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css {
<link href="~/Content/css/register.css" rel="stylesheet" />
}
@section javascript {
<script src="~/content/js/jquery.validate.js"></script>
<script src="~/content/js/messages_zh.js"></script>
<script src="~/Scripts/register.js"></script>
}
<div class="container">
<div class="setup-wrapper">
<div class="setup-header">
<ol class="steps">
<li class="current">
<strong class="step">步骤 1:</strong><span>创建一个账号</span>
</li>
<li>
<strong class="step">步骤 2:</strong><span>确认信息</span>
</li>
</ol>
</div>
<form autocomplete="off" id="signup-form" method="post">
<div class="setup-main">
<div class="setup-form-container">
<h2 class="setup-form-title mb-3">
创建您的账号
</h2>
<label for="userName">登陆账号:</label>
<div class="input-group">
<span class="input-group-addon">@@</span>
<input type="text" id="userName" name="userName" class="form-control" placeholder="登陆账号" value="" autofocus />
</div>
<label for="displayName">显示名称:</label>
<div class="input-group">
<span class="glyphicon glyphicon-user input-group-addon"></span>
<input type="text" id="displayName" name="displayName" class="form-control" value="" placeholder="显示名称" />
</div>
<label for="password">密码:</label>
<div class="input-group">
<span class="glyphicon glyphicon-lock input-group-addon"></span>
<input type="password" id="password" name="password" class="form-control" value="" placeholder="密码" />
</div>
<button id="btnAccount" class="btn btn-primary" type="button">继续</button>
</div> <!-- /.setup-form-container -->
</div>
<div class="setup-confirm">
<h4>您注册的信息如下:</h4>
<div>
<label>登陆账号:</label><span></span>
</div>
<div>
<label>显示名称:</label><span></span>
</div>
<button id="btnSubmit" class="btn btn-primary" type="submit">确认并提交</button>
</div>
</form>
<div class="setup-secondary">
<div class="setup-info-module">
<h4>欢迎加入本系统</h4>
<ul class="features-list">
<li><strong>Unlimited</strong>特性一</li>
<li><strong>Unlimited</strong>特性二</li>
<li class="list-divider"></li>
<li><i class="glyphicon glyphicon-ok"></i>优点一</li>
<li><i class="glyphicon glyphicon-ok"></i>优点二</li>
<li><i class="glyphicon glyphicon-ok"></i>优点三</li>
</ul>
</div>
</div>
</div>
</div>

View File

@ -1,4 +1,6 @@
namespace Bootstrap.DataAccess
using System;
namespace Bootstrap.DataAccess
{
/// <summary>
/// 用户表实体类
@ -21,5 +23,13 @@
/// 获取/设置 角色用户关联状态 checked 标示已经关联 '' 标示未关联
/// </summary>
public string Checked { get; set; }
/// <summary>
/// 获得/设置 用户注册时间
/// </summary>
public DateTime RegisterTime { get; set; }
/// <summary>
/// 获得/设置 用户被批复时间
/// </summary>
public DateTime ApprovedTime { get; set; }
}
}

View File

@ -30,7 +30,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<User> RetrieveUsers(string tId = null)
{
string sql = "select ID, UserName, DisplayName from Users";
string sql = "select ID, UserName, DisplayName, RegisterTime, ApprovedTime from Users Where ApprovedTime is not null";
var ret = CacheManager.GetOrAdd(RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersDataKey), key =>
{
List<User> Users = new List<User>();
@ -45,7 +45,9 @@ namespace Bootstrap.DataAccess
{
ID = (int)reader[0],
UserName = (string)reader[1],
DisplayName = (string)reader[2]
DisplayName = (string)reader[2],
RegisterTime = (DateTime)reader[3],
ApprovedTime = (DateTime)reader[4]
});
}
}
@ -67,7 +69,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
{
User user = null;
string sql = "select ID, UserName, [Password], PassSalt, DisplayName from Users where UserName = @UserName";
string sql = "select ID, UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime from Users where ApprovedTime is not null and UserName = @UserName";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
@ -82,7 +84,9 @@ namespace Bootstrap.DataAccess
UserName = (string)reader[1],
Password = (string)reader[2],
PassSalt = (string)reader[3],
DisplayName = (string)reader[4]
DisplayName = (string)reader[4],
RegisterTime = (DateTime)reader[5],
ApprovedTime = (DateTime)reader[6]
};
}
}
@ -129,7 +133,7 @@ namespace Bootstrap.DataAccess
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
if (p.DisplayName.Length > 50) p.DisplayName.Substring(0, 50);
string sql = p.ID == 0 ?
"Insert Into Users (UserName, Password, PassSalt, DisplayName) Values (@UserName, @Password, @PassSalt, @DisplayName)" :
"Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime) Values (@UserName, @Password, @PassSalt, @DisplayName, GetDate(), @ApprovedTime)" :
"Update Users set UserName = @UserName, Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @ID";
try
{
@ -140,6 +144,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", p.Password, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", p.PassSalt, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", p.DisplayName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApprovedTime", DBAccess.ToDBValue(p.ApprovedTime), ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
CacheCleanUtility.ClearCache(userIds: p.ID == 0 ? "" : p.ID.ToString());
@ -173,7 +178,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
{
List<User> Users = new List<User>();
string sql = "select u.ID,u.UserName,u.DisplayName,case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID=ur.UserID and RoleID =@RoleID";
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", roleId, ParameterDirection.Input));
try
@ -251,7 +256,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByGroupIDDataKey), k =>
{
List<User> Users = new List<User>();
string sql = "select u.ID,u.UserName,u.DisplayName,case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID=ur.UserID and GroupID =@groupId";
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", groupId, ParameterDirection.Input));
try
@ -292,7 +297,7 @@ namespace Bootstrap.DataAccess
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserGroup where GroupID=@GroupID";
string sql = "delete from UserGroup where GroupID = @GroupID";
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id, ParameterDirection.Input));
@ -318,5 +323,15 @@ namespace Bootstrap.DataAccess
}
return ret;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static bool RegisterUser(string userName, string displayName, string password)
{
//TODO判断注册用户是否合理判断合法后插入数据库中返回真并通知管理员组有新用户注册需要批复。数据库Users表中增加一个字段标示用户是否被批复
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(password)) return false;
return SaveUser(new User() { UserName = userName, DisplayName = displayName, Password = password });
}
}
}

View File

@ -3,7 +3,7 @@ GO
DELETE From Users where ID = 1
SET IDENTITY_INSERT [dbo].[Users] ON
insert into Users (ID, UserName, Password, PassSalt, DisplayName) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator')
insert into Users (ID, UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', GetDate(), GetDate())
SET IDENTITY_INSERT [dbo].[Users] OFF
DELETE From Dicts where ID in (1, 2, 3, 4)

View File

@ -1,4 +1,4 @@
USE [master]
USE [master]
GO
Create database [BootstrapAdmin]
GO
@ -9,33 +9,56 @@ GO
USE [BootstrapAdmin]
GO
/****** Object: Table [dbo].[Users] Script Date: 10/24/2016 15:48:24 ******/
/****** Object: Table [dbo].[Users] Script Date: 11/06/2016 15:23:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
[ID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](50) NOT NULL,
[Password] [varchar](50) NOT NULL,
[PassSalt] [varchar](50) NOT NULL,
[DisplayName] [nvarchar](50) NOT NULL,
[ID] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](50) NOT NULL,
[Password] [varchar](50) NOT NULL,
[PassSalt] [varchar](50) NOT NULL,
[DisplayName] [nvarchar](50) NOT NULL,
[RegisterTime] [datetime] NOT NULL,
[ApprovedTime] [datetime] NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[ID] ASC
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'ID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'用户名' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'UserName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'密码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'Password'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'密码盐' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'PassSalt'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'显示名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'DisplayName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'注册时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'RegisterTime'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'批复时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Users', @level2type=N'COLUMN',@level2name=N'ApprovedTime'
GO
/****** Object: Table [dbo].[Groups] Script Date: 10/22/2016 09:44:03 ******/
SET ANSI_NULLS ON
GO