сброс пароля

This commit is contained in:
kotcheshir73 2021-04-12 12:35:05 +04:00
parent 4fc7c24c81
commit 11cb574c3a
2 changed files with 66 additions and 2 deletions

View File

@ -10,6 +10,7 @@ using ModuleTools.BusinessLogics;
using ModuleTools.Extensions; using ModuleTools.Extensions;
using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.BusinessLogics; using SecurityBusinessLogic.BusinessLogics;
using SecurityBusinessLogic.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -36,7 +37,8 @@ namespace DepartmentWindowsDesktop.EntityControls
{ {
ControlOnMoveElem = new Dictionary<string, (string Title, EventHandler Event)> ControlOnMoveElem = new Dictionary<string, (string Title, EventHandler Event)>
{ {
{ "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) },
{ "ToolStripMenuItemPasswordReset", ("Сброс пароля пользователя", (object sender, EventArgs e) => { PasswordReset(); }) }
} }
}; };
@ -85,5 +87,35 @@ namespace DepartmentWindowsDesktop.EntityControls
} }
} }
} }
/// <summary>
/// Сброс пароля пользователя
/// </summary>
private void PasswordReset()
{
if (_element == null)
{
return;
}
var model = new EmployeeSetBindingModel();
if (FillModel(model))
{
var logic = DependencyManager.Instance.Resolve<UserBusinessLogic>();
var user = logic.GetElement(new UserGetBindingModel { Id = _element.UserId });
if (user == null)
{
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return;
}
user.Password = model.DateBirth.ToShortDateString();
user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true));
if (user == null)
{
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return;
}
DialogHelper.MessageInformation("Пароль сброшен", "Успех");
}
}
} }
} }

View File

@ -10,6 +10,7 @@ using ModuleTools.BusinessLogics;
using ModuleTools.Extensions; using ModuleTools.Extensions;
using SecurityBusinessLogic.BindingModels; using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.BusinessLogics; using SecurityBusinessLogic.BusinessLogics;
using SecurityBusinessLogic.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -33,7 +34,8 @@ namespace DepartmentWindowsDesktop.EntityControls
{ {
ControlOnMoveElem = new Dictionary<string, (string Title, EventHandler Event)> ControlOnMoveElem = new Dictionary<string, (string Title, EventHandler Event)>
{ {
{ "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) } { "ToolStripMenuItemAddUser", ("Добавить пользователя", (object sender, EventArgs e) => { AddUser(); }) },
{ "ToolStripMenuItemPasswordReset", ("Сброс пароля пользователя", (object sender, EventArgs e) => { PasswordReset(); }) }
} }
}; };
@ -82,5 +84,35 @@ namespace DepartmentWindowsDesktop.EntityControls
} }
} }
} }
/// <summary>
/// Сброс пароля пользователя
/// </summary>
private void PasswordReset()
{
if (_element == null)
{
return;
}
var model = new LecturerSetBindingModel();
if (FillModel(model))
{
var logic = DependencyManager.Instance.Resolve<UserBusinessLogic>();
var user = logic.GetElement(new UserGetBindingModel { Id = _element.UserId });
if (user == null)
{
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return;
}
user.Password = model.DateBirth.ToShortDateString();
user = logic.Update(Mapper.MapToClass<UserViewModel, UserSetBindingModel>(user, true));
if (user == null)
{
DialogHelper.MessageException(logic.Errors, "Ошибка при получении пользователя");
return;
}
DialogHelper.MessageInformation("Пароль сброшен", "Успех");
}
}
} }
} }