-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
267 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
RabbitCMS/Web/Modules/Rabbit.Users/Controllers/UserAdminController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Rabbit.Components.Security; | ||
using Rabbit.Infrastructures.Mvc; | ||
using Rabbit.Infrastructures.Security; | ||
using Rabbit.Users.Services; | ||
using Rabbit.Users.ViewModels; | ||
using Rabbit.Web.Mvc.UI.Admin; | ||
using System.Web.Mvc; | ||
|
||
namespace Rabbit.Users.Controllers | ||
{ | ||
[Admin] | ||
public class UserAdminController : Controller | ||
{ | ||
private readonly IAuthenticationService _authenticationService; | ||
private readonly IUserService _userService; | ||
|
||
public UserAdminController(IAuthenticationService authenticationService, IUserService userService) | ||
{ | ||
_authenticationService = authenticationService; | ||
_userService = userService; | ||
} | ||
|
||
public ActionResult Edit(string id) | ||
{ | ||
var user = _userService.GetUserById(id ?? _authenticationService.GetAuthenticatedUser().Identity); | ||
if (user == null) | ||
return HttpNotFound(); | ||
|
||
var model = (UserEditViewModel)user; | ||
return View(model); | ||
} | ||
|
||
[ValidateAntiForgeryToken, HttpPost] | ||
public ActionResult Edit(UserEditViewModel model) | ||
{ | ||
if (!ModelState.IsValid) | ||
return this.Error("数据非法!"); | ||
|
||
var user = _userService.GetUserById(model.Id); | ||
if (user == null) | ||
return this.Error("数据非法!"); | ||
|
||
model.UpdateRecord(user); | ||
|
||
var userModel = _authenticationService.GetAuthenticatedUser() as UserModel; | ||
if (userModel != null && userModel.Identity == user.Id) | ||
{ | ||
userModel.UserName = user.Name; | ||
_authenticationService.SignIn(userModel, userModel.CreatePersistentCookie); | ||
} | ||
|
||
return this.Success(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
RabbitCMS/Web/Modules/Rabbit.Users/ViewModels/UserViewModels.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Rabbit.Users.Models; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Rabbit.Users.ViewModels | ||
{ | ||
public class UserEditViewModel | ||
{ | ||
public string Id { get; set; } | ||
|
||
[DisplayName("用户名称"), Required, StringLength(20)] | ||
public string UserName { get; set; } | ||
|
||
[DisplayName("账号名称"), Required, StringLength(20)] | ||
public string AccountName { get; set; } | ||
|
||
[DisplayName("密码"), StringLength(20, MinimumLength = 5)] | ||
public string Password { get; set; } | ||
|
||
[DisplayName("确认密码"), Compare("Password")] | ||
public string ConfirmPassword { get; set; } | ||
|
||
public static explicit operator UserEditViewModel(UserRecord record) | ||
{ | ||
return new UserEditViewModel | ||
{ | ||
Id = record.Id, | ||
AccountName = record.Account.Account, | ||
Password = record.Account.Password, | ||
UserName = record.Name | ||
}; | ||
} | ||
|
||
public UserRecord UpdateRecord(UserRecord record) | ||
{ | ||
record.Name = UserName; | ||
record.Account.Account = AccountName; | ||
if (!string.IsNullOrEmpty(Password)) | ||
record.Account.SetPassword(Password); | ||
|
||
return record; | ||
} | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
RabbitCMS/Web/Modules/Rabbit.Users/Views/UserAdmin/Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
@using System.Web.Optimization | ||
@model Rabbit.Users.ViewModels.UserEditViewModel | ||
@helper PageStyles() | ||
{ | ||
<style type="text/css"> | ||
.field-validation-error { | ||
color: #dd4b39; | ||
} | ||
</style> | ||
<link href="~/Themes/TheAdmin/lib/iCheck/all.css" rel="stylesheet" /> | ||
} | ||
@helper PageScripts() | ||
{ | ||
@Scripts.Render("~/bundles/jqueryvalidate", "~/bundles/jqueryform") | ||
<script src="~/Themes/TheAdmin/lib/iCheck/icheck.min.js"></script> | ||
<script type="text/javascript"> | ||
var container = $(".box-info"); | ||
var form = container.find("form"); | ||
var dialog=$(".alert-dismissable"); | ||
form.ajaxForm({ | ||
beforeSerialize: function () { | ||
}, | ||
beforeSubmit: function (array, f) { | ||
return f.valid(); | ||
}, | ||
success: function (data) { | ||
dialog.removeClass("alert-danger", "alert-success"); | ||
if (data.success) { | ||
dialog.addClass("alert-success"); | ||
dialog.find("span").html("保存成功!"); | ||
} else { | ||
dialog.addClass("alert-danger"); | ||
dialog.find("span").html("保存失败,"+data.message); | ||
} | ||
dialog.fadeIn(function() { | ||
setTimeout(function() { | ||
dialog.fadeOut(); | ||
}, 1500); | ||
}); | ||
}, | ||
error: function () { | ||
dialog.removeClass("alert-danger", "alert-success").addClass("alert-danger"); | ||
dialog.find("span").html("保存失败,请联系管理员!"); | ||
dialog.fadeIn(function () { | ||
setTimeout(function () { | ||
dialog.fadeOut(); | ||
}, 1500); | ||
}); | ||
} | ||
}); | ||
</script> | ||
} | ||
@{ | ||
Layout.Styles = PageStyles(); | ||
Layout.Scripts = PageScripts(); | ||
var title = "编辑用户 - " + Model.UserName; | ||
Layout.Title = title; | ||
} | ||
|
||
<div class="alert alert-danger alert-dismissable" style="display: none"> | ||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> | ||
<h4><i class="icon fa fa-ban"></i> <span>删除失败,请联系管理员!</span></h4> | ||
</div> | ||
<div class="box box-info"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title">@title</h3> | ||
</div><!-- /.box-header --> | ||
<!-- form start --> | ||
<form method="POST" class="form-horizontal"> | ||
@Html.HiddenFor(model=>model.Id) | ||
@Html.AntiForgeryToken() | ||
<div class="box-body"> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">@Html.DisplayNameFor(model => model.UserName)</label> | ||
<div class="col-sm-10"> | ||
<div class="col-sm-8"> | ||
@Html.TextBoxFor(model => model.UserName, new {@class = "form-control"}) | ||
</div> | ||
<div class="col-sm-2"> | ||
@Html.ValidationMessageFor(model => model.UserName) | ||
</div> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">@Html.DisplayNameFor(model => model.AccountName)</label> | ||
<div class="col-sm-10"> | ||
<div class="col-sm-8"> | ||
@Html.TextBoxFor(model => model.AccountName, new {@class = "form-control"}) | ||
</div> | ||
<div class="col-sm-2"> | ||
@Html.ValidationMessageFor(model => model.AccountName) | ||
</div> | ||
</div> | ||
</div> | ||
<div class="box box-warning collapsed-box"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title" data-widget="collapse" style="cursor: pointer"> | ||
修改密码 | ||
<small>(留空则不修改)</small> | ||
</h3> | ||
<div class="box-tools pull-right"> | ||
<button class="btn btn-box-tool" data-widget="collapse" title="折叠"><i class="fa fa-plus"></i></button> | ||
</div> | ||
</div> | ||
<div class="box-body"> | ||
<div class="form-horizontal"> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">@Html.DisplayNameFor(model => model.Password)</label> | ||
<div class="col-sm-10"> | ||
<div class="col-sm-8"> | ||
@Html.PasswordFor(model => model.Password, new {@class = "form-control"}) | ||
</div> | ||
<div class="col-sm-2"> | ||
@Html.ValidationMessageFor(model => model.Password) | ||
</div> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">@Html.DisplayNameFor(model => model.ConfirmPassword)</label> | ||
<div class="col-sm-10"> | ||
<div class="col-sm-8"> | ||
@Html.PasswordFor(model => model.ConfirmPassword, new {@class = "form-control"}) | ||
</div> | ||
<div class="col-sm-2"> | ||
@Html.ValidationMessageFor(model => model.ConfirmPassword) | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div><!-- /.box-body --> | ||
</div> | ||
</div><!-- /.box-body --> | ||
<div class="box-footer" style="text-align: center"> | ||
<button type="submit" class="btn btn-info">保存</button> | ||
<button type="submit" class="btn btn-default">取消</button> | ||
</div><!-- /.box-footer --> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters