Update vor Clone
This commit is contained in:
@@ -15,12 +15,12 @@
|
||||
@using BlazorApp.Controller;
|
||||
|
||||
|
||||
<h1>AspNetUserRolle</h1>
|
||||
<h1>BenutzerListe</h1>
|
||||
|
||||
<div class="col-lg-12 control-section">
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<SfGrid DataSource="@GridData" @ref="Grid" AllowPaging="true" AllowSelection="true" AllowSorting="true" Toolbar="@(new List<string>() { "Add", "Edit", "Update", "Cancel", "Passwort ändern" })">
|
||||
<SfGrid DataSource="@GridData" @ref="Grid" AllowPaging="true" AllowSelection="true" AllowSorting="true" Toolbar="@(new List<string>() { "Edit", "Update", "Cancel", "Passwort ändern","Benutzer erstellen" })">
|
||||
<GridPageSettings PageCount="5" PageSizes="true"></GridPageSettings>
|
||||
<GridEditSettings AllowAdding="false" AllowDeleting="false" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
|
||||
<GridEvents RowSelected="GetSelectedRecords" OnActionBegin="OnBeginHandler" OnActionComplete="OnCompletedHandler" TValue="BWPMModels.AspNetUserRolle" OnToolbarClick="ToolBarClickHandler" OnDataBound="RowDataBoundHandler"></GridEvents>
|
||||
@@ -86,14 +86,53 @@
|
||||
<DialogButton Content="Abbruch" OnClick="@CloseDialog" />
|
||||
</DialogButtons>
|
||||
</SfDialog>
|
||||
|
||||
<SfDialog Width="400px" IsModal="true" @bind-Visible="@NewUserIsVisible">
|
||||
<DialogEvents OnOverlayClick="@OnOverlayclick">
|
||||
</DialogEvents>
|
||||
<DialogTemplates>
|
||||
<Header>Neuer Benutzer erstellen</Header>
|
||||
<Content>
|
||||
|
||||
<label style="color:red">@ErrorMsg</label><br />
|
||||
<SfRadioButton Label="Administrator" Name="options" Value="Administrators" @bind-Checked="stringChecked"></SfRadioButton>
|
||||
<SfRadioButton Label="Firma" Name="options" Value="Firma" @bind-Checked="stringChecked"></SfRadioButton>
|
||||
<SfRadioButton Label="Lehrer" Name="options" Value="Lehrer" @bind-Checked="stringChecked"></SfRadioButton><BR /><BR />
|
||||
|
||||
<label>
|
||||
E-Mail (Benutzername):
|
||||
<input type="email" @bind-value="newusername" id="username" name="Required" class="e-input">
|
||||
Passwort
|
||||
<input type="password" @bind-value="newpassword" id="password" name="Required" class="e-input">
|
||||
Passwort-Bestätigung
|
||||
<input type="password" @bind-value="newpassword1" id="password1" name="Required" class="e-input">
|
||||
</label>
|
||||
|
||||
</Content>
|
||||
</DialogTemplates>
|
||||
<DialogButtons>
|
||||
<DialogButton Content="OK" IsPrimary="true" OnClick="@SaveNewUser" />
|
||||
<DialogButton Content="Abbruch" OnClick="@CloseDialog" />
|
||||
</DialogButtons>
|
||||
</SfDialog>
|
||||
@code{
|
||||
|
||||
|
||||
private bool IsVisible { get; set; } = false;
|
||||
private bool NewUserIsVisible { get; set; } = false;
|
||||
|
||||
private string Gridid = "";
|
||||
public List<BWPMModels.AspNetUserRolle> Temp { get; set; }
|
||||
public List<BWPMModels.AspNetUsers> TempUser { get; set; }
|
||||
public List<BWPMModels.AspNetRoles> TmpRolle { get; set; }
|
||||
public List<BWPMModels.AspNetUserRoles> TmpUserRoles { get; set; }
|
||||
private string newpassword { get; set; } = "";
|
||||
private string newusername { get; set; } = "";
|
||||
private string newpassword1 { get; set; } = "";
|
||||
private string ErrorMsg { get; set; } = "";
|
||||
private string Username { get; set; } = "";
|
||||
private string stringChecked { get; set; } = "Administrators";
|
||||
|
||||
|
||||
SfGrid<BWPMModels.AspNetUserRolle> Grid { get; set; }
|
||||
|
||||
@@ -101,14 +140,28 @@
|
||||
{
|
||||
this.IsVisible = false;
|
||||
}
|
||||
private void ShowDialog()
|
||||
private void ShowDialog(int dialognr)
|
||||
{
|
||||
|
||||
this.ErrorMsg = "";
|
||||
this.IsVisible = true; ;
|
||||
switch (dialognr)
|
||||
{
|
||||
case 1:
|
||||
this.IsVisible = true;
|
||||
break;
|
||||
case 2:
|
||||
this.NewUserIsVisible = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
this.IsVisible = false; ;
|
||||
this.IsVisible = false;
|
||||
this.NewUserIsVisible = false;
|
||||
}
|
||||
private void SavePasswort()
|
||||
{
|
||||
@@ -133,6 +186,73 @@
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveNewUser()
|
||||
{
|
||||
ErrorMsg = "";
|
||||
if (newusername.Trim()=="")
|
||||
{
|
||||
ErrorMsg = "Benutzername fehlt.";
|
||||
return;
|
||||
}
|
||||
if ((newpassword.Trim()=="") && (newpassword1.Trim()=="" ))
|
||||
{
|
||||
ErrorMsg = "Passwort fehlt.";
|
||||
return;
|
||||
}
|
||||
if(newpassword != newpassword1)
|
||||
{
|
||||
ErrorMsg = "Passworte stimmen nicht überein";
|
||||
return;
|
||||
}
|
||||
|
||||
BlazorApp.Helper.Utils utl = new BlazorApp.Helper.Utils();
|
||||
if (utl.IsValidEmail(newusername) !=true){
|
||||
ErrorMsg = "Benutzername ist ungültig (E-Mail Adresse)";
|
||||
return;
|
||||
}
|
||||
|
||||
TempUser= BlazorApp.Controller.AspNetUsersController.GetByEMail(newusername);
|
||||
if (TempUser.Count !=0)
|
||||
{
|
||||
ErrorMsg = "Benutzer bereits vorhanden.";
|
||||
return;
|
||||
}
|
||||
|
||||
BWPMModels.AspNetUsers usr = new BWPMModels.AspNetUsers();
|
||||
usr.UserName=newusername;
|
||||
usr.NormalizedUserName=newusername.ToUpper();
|
||||
usr.NormalizedEmail = newusername.ToUpper();
|
||||
usr.Email=newusername;
|
||||
usr.EmailConfirmed=true;
|
||||
Guid g = Guid.NewGuid();
|
||||
usr.Id = g.ToString();
|
||||
|
||||
IdentityUser objUser = new IdentityUser();
|
||||
objUser.Id = g.ToString();
|
||||
var password = _UserManager.PasswordHasher.HashPassword(objUser,newpassword);
|
||||
usr.PasswordHash=password;
|
||||
usr.SecurityStamp = Guid.NewGuid().ToString();
|
||||
usr.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||
usr.PhoneNumber="";
|
||||
usr.PhoneNumberConfirmed=false;
|
||||
usr.TwoFactorEnabled = false;
|
||||
usr.LockoutEnabled=true;
|
||||
usr.AccessFailedCount = 0;
|
||||
BlazorApp.Controller.AspNetUsersController.POST(usr);
|
||||
|
||||
TmpRolle = BlazorApp.Controller.AspNetRolesController.GetByName(stringChecked);
|
||||
var _tmprolle = new BWPMModels.AspNetRoles();
|
||||
_tmprolle = TmpRolle.First<BWPMModels.AspNetRoles>();
|
||||
var usrrole = new BWPMModels.AspNetUserRoles();
|
||||
usrrole.UserId = g.ToString();
|
||||
usrrole.RoleId = _tmprolle.Id;
|
||||
BlazorApp.Controller.AspNetUserRolesController.POST(usrrole);
|
||||
|
||||
this.NewUserIsVisible=false;
|
||||
Grid.Refresh();
|
||||
|
||||
}
|
||||
|
||||
public async Task ToolBarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
|
||||
{
|
||||
if (args.Item.Text == "Passwort ändern")
|
||||
@@ -143,9 +263,13 @@
|
||||
{
|
||||
Username = temp[0].UserName;
|
||||
Gridid = temp[0].Id;
|
||||
ShowDialog();
|
||||
ShowDialog(1);
|
||||
}
|
||||
}
|
||||
if (args.Item.Text == "Benutzer erstellen")
|
||||
{
|
||||
ShowDialog(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -155,8 +279,6 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<BWPMModels.AspNetUserRolle> GridData { get; set; }
|
||||
public List<BWPMModels.AspNetUserRolle> AspNetUserRolles { get; set; }
|
||||
public List<BWPMModels.AspNetRoles> AspNetRoles { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user