SKE-58 add participant class to register
This commit is contained in:
parent
2fc97f469c
commit
79e797edeb
@ -38,6 +38,32 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-float">
|
||||||
|
<div class="form-line">
|
||||||
|
<select class="form-control"
|
||||||
|
[(ngModel)]="model.role"
|
||||||
|
name="Role"
|
||||||
|
required>
|
||||||
|
<option *ngFor="let possibleRole of possibleRoles" [value]="possibleRole.value">
|
||||||
|
{{possibleRole.viewValue}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="model.role === 'Participant'" class="form-group form-float">
|
||||||
|
<div class="form-line">
|
||||||
|
<select class="form-control"
|
||||||
|
[(ngModel)]="model.participantClass"
|
||||||
|
name="ParticipantClass"
|
||||||
|
required>
|
||||||
|
<option *ngFor="let possibleClass of possibleClasses" [value]="possibleClass.value">
|
||||||
|
{{possibleClass.viewValue}}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button [disabled]="saving" [routerLink]="['../login']" type="button" class="btn btn-default">{{l("Powrót")}}</button>
|
<button [disabled]="saving" [routerLink]="['../login']" type="button" class="btn btn-default">{{l("Powrót")}}</button>
|
||||||
<button type="submit" class="btn btn-success" [disabled]="!registerForm.form.valid">{{l("Zarejestruj")}}</button>
|
<button type="submit" class="btn btn-success" [disabled]="!registerForm.form.valid">{{l("Zarejestruj")}}</button>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, Injector, ElementRef, AfterViewInit, ViewChild } from '@angular/core';
|
import { Component, Injector, ElementRef, OnInit, AfterViewInit, ViewChild } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { AccountServiceProxy, RegisterInput, RegisterOutput } from '@shared/service-proxies/service-proxies'
|
import { AccountServiceProxy, RegisterInput, RegisterOutput } from '@shared/service-proxies/service-proxies'
|
||||||
import { AppComponentBase } from '@shared/app-component-base';
|
import { AppComponentBase } from '@shared/app-component-base';
|
||||||
@ -10,7 +10,7 @@ import { finalize } from 'rxjs/operators';
|
|||||||
templateUrl: './register.component.html',
|
templateUrl: './register.component.html',
|
||||||
animations: [accountModuleAnimation()]
|
animations: [accountModuleAnimation()]
|
||||||
})
|
})
|
||||||
export class RegisterComponent extends AppComponentBase implements AfterViewInit {
|
export class RegisterComponent extends AppComponentBase implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
@ViewChild('cardBody') cardBody: ElementRef;
|
@ViewChild('cardBody') cardBody: ElementRef;
|
||||||
|
|
||||||
@ -18,6 +18,22 @@ export class RegisterComponent extends AppComponentBase implements AfterViewInit
|
|||||||
|
|
||||||
saving: boolean = false;
|
saving: boolean = false;
|
||||||
|
|
||||||
|
public possibleClasses = [
|
||||||
|
{value: 1, viewValue: 'Klasa 1'},
|
||||||
|
{value: 2, viewValue: 'Klasa 2'},
|
||||||
|
{value: 3, viewValue: 'Klasa 3'},
|
||||||
|
{value: 4, viewValue: 'Klasa 4'},
|
||||||
|
{value: 5, viewValue: 'Klasa 5'},
|
||||||
|
{value: 6, viewValue: 'Klasa 6'},
|
||||||
|
{value: 7, viewValue: 'Klasa 7'},
|
||||||
|
{value: 8, viewValue: 'Klasa 8'}
|
||||||
|
];
|
||||||
|
|
||||||
|
public possibleRoles = [
|
||||||
|
{value: 'Participant', viewValue: 'Uczestnik'},
|
||||||
|
{value: 'Organizer', viewValue: 'Organizator'}
|
||||||
|
];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
injector: Injector,
|
injector: Injector,
|
||||||
private _accountService: AccountServiceProxy,
|
private _accountService: AccountServiceProxy,
|
||||||
@ -30,12 +46,22 @@ export class RegisterComponent extends AppComponentBase implements AfterViewInit
|
|||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
$(this.cardBody.nativeElement).find('input:first').focus();
|
$(this.cardBody.nativeElement).find('input:first').focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.model.role = 'Participant';
|
||||||
|
this.model.participantClass = 1;
|
||||||
|
}
|
||||||
|
|
||||||
back(): void {
|
back(): void {
|
||||||
this._router.navigate(['/login']);
|
this._router.navigate(['/login']);
|
||||||
}
|
}
|
||||||
|
|
||||||
save(): void {
|
save(): void {
|
||||||
|
if (this.model.role === 'Organizer') {
|
||||||
|
this.model.participantClass = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.model.participantClass = +this.model.participantClass;
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
this._accountService.register(this.model)
|
this._accountService.register(this.model)
|
||||||
.pipe(finalize(() => { this.saving = false; }))
|
.pipe(finalize(() => { this.saving = false; }))
|
||||||
|
@ -1880,6 +1880,8 @@ export class RegisterInput implements IRegisterInput {
|
|||||||
userName: string;
|
userName: string;
|
||||||
emailAddress: string;
|
emailAddress: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
role: string;
|
||||||
|
participantClass: number;
|
||||||
captchaResponse: string | undefined;
|
captchaResponse: string | undefined;
|
||||||
|
|
||||||
constructor(data?: IRegisterInput) {
|
constructor(data?: IRegisterInput) {
|
||||||
@ -1898,6 +1900,8 @@ export class RegisterInput implements IRegisterInput {
|
|||||||
this.userName = data["userName"];
|
this.userName = data["userName"];
|
||||||
this.emailAddress = data["emailAddress"];
|
this.emailAddress = data["emailAddress"];
|
||||||
this.password = data["password"];
|
this.password = data["password"];
|
||||||
|
this.role = data["role"];
|
||||||
|
this.participantClass = data["participantClass"];
|
||||||
this.captchaResponse = data["captchaResponse"];
|
this.captchaResponse = data["captchaResponse"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1916,6 +1920,8 @@ export class RegisterInput implements IRegisterInput {
|
|||||||
data["userName"] = this.userName;
|
data["userName"] = this.userName;
|
||||||
data["emailAddress"] = this.emailAddress;
|
data["emailAddress"] = this.emailAddress;
|
||||||
data["password"] = this.password;
|
data["password"] = this.password;
|
||||||
|
data["role"] = this.role;
|
||||||
|
data["participantClass"] = this.participantClass;
|
||||||
data["captchaResponse"] = this.captchaResponse;
|
data["captchaResponse"] = this.captchaResponse;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@ -1934,6 +1940,8 @@ export interface IRegisterInput {
|
|||||||
userName: string;
|
userName: string;
|
||||||
emailAddress: string;
|
emailAddress: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
role: string;
|
||||||
|
participantClass: number;
|
||||||
captchaResponse: string | undefined;
|
captchaResponse: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,8 @@ namespace SystemKonkursow.Authorization.Accounts
|
|||||||
input.EmailAddress,
|
input.EmailAddress,
|
||||||
input.UserName,
|
input.UserName,
|
||||||
input.Password,
|
input.Password,
|
||||||
|
input.Role,
|
||||||
|
input.ParticipantClass,
|
||||||
true // Assumed email address is always confirmed. Change this if you want to implement email confirmation.
|
true // Assumed email address is always confirmed. Change this if you want to implement email confirmation.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -31,6 +31,12 @@ namespace SystemKonkursow.Authorization.Accounts.Dto
|
|||||||
[DisableAuditing]
|
[DisableAuditing]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Role { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int ParticipantClass { get; set; }
|
||||||
|
|
||||||
[DisableAuditing]
|
[DisableAuditing]
|
||||||
public string CaptchaResponse { get; set; }
|
public string CaptchaResponse { get; set; }
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ using Abp.Runtime.Session;
|
|||||||
using Abp.UI;
|
using Abp.UI;
|
||||||
using SystemKonkursow.Authorization.Roles;
|
using SystemKonkursow.Authorization.Roles;
|
||||||
using SystemKonkursow.MultiTenancy;
|
using SystemKonkursow.MultiTenancy;
|
||||||
|
using SystemKonkursow.Domain;
|
||||||
|
using Abp.Domain.Repositories;
|
||||||
|
|
||||||
namespace SystemKonkursow.Authorization.Users
|
namespace SystemKonkursow.Authorization.Users
|
||||||
{
|
{
|
||||||
@ -22,22 +24,25 @@ namespace SystemKonkursow.Authorization.Users
|
|||||||
private readonly UserManager _userManager;
|
private readonly UserManager _userManager;
|
||||||
private readonly RoleManager _roleManager;
|
private readonly RoleManager _roleManager;
|
||||||
private readonly IPasswordHasher<User> _passwordHasher;
|
private readonly IPasswordHasher<User> _passwordHasher;
|
||||||
|
private readonly IRepository<Domain.Participant, int> _participantRepository;
|
||||||
|
|
||||||
public UserRegistrationManager(
|
public UserRegistrationManager(
|
||||||
TenantManager tenantManager,
|
TenantManager tenantManager,
|
||||||
UserManager userManager,
|
UserManager userManager,
|
||||||
RoleManager roleManager,
|
RoleManager roleManager,
|
||||||
IPasswordHasher<User> passwordHasher)
|
IPasswordHasher<User> passwordHasher,
|
||||||
|
IRepository<Domain.Participant, int> participantRepository)
|
||||||
{
|
{
|
||||||
_tenantManager = tenantManager;
|
_tenantManager = tenantManager;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_roleManager = roleManager;
|
_roleManager = roleManager;
|
||||||
_passwordHasher = passwordHasher;
|
_passwordHasher = passwordHasher;
|
||||||
|
_participantRepository = participantRepository;
|
||||||
|
|
||||||
AbpSession = NullAbpSession.Instance;
|
AbpSession = NullAbpSession.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<User> RegisterAsync(string name, string surname, string emailAddress, string userName, string plainPassword, bool isEmailConfirmed)
|
public async Task<User> RegisterAsync(string name, string surname, string emailAddress, string userName, string plainPassword, string role, int participantClass, bool isEmailConfirmed)
|
||||||
{
|
{
|
||||||
CheckForTenant();
|
CheckForTenant();
|
||||||
|
|
||||||
@ -56,7 +61,19 @@ namespace SystemKonkursow.Authorization.Users
|
|||||||
};
|
};
|
||||||
|
|
||||||
user.SetNormalizedNames();
|
user.SetNormalizedNames();
|
||||||
|
|
||||||
|
if (role == "Participant")
|
||||||
|
{
|
||||||
|
var participantRole = _roleManager.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == tenant.Id && r.Name == StaticRoleNames.Host.Participant);
|
||||||
|
user.Roles.Add(new UserRole(tenant.Id, user.Id, participantRole.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (role == "Organizer")
|
||||||
|
{
|
||||||
|
var organizerRole = _roleManager.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == tenant.Id && r.Name == StaticRoleNames.Host.Organizer);
|
||||||
|
user.Roles.Add(new UserRole(tenant.Id, user.Id, organizerRole.Id));
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())
|
foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync())
|
||||||
{
|
{
|
||||||
user.Roles.Add(new UserRole(tenant.Id, user.Id, defaultRole.Id));
|
user.Roles.Add(new UserRole(tenant.Id, user.Id, defaultRole.Id));
|
||||||
@ -65,6 +82,18 @@ namespace SystemKonkursow.Authorization.Users
|
|||||||
await _userManager.InitializeOptionsAsync(tenant.Id);
|
await _userManager.InitializeOptionsAsync(tenant.Id);
|
||||||
|
|
||||||
CheckErrors(await _userManager.CreateAsync(user, plainPassword));
|
CheckErrors(await _userManager.CreateAsync(user, plainPassword));
|
||||||
|
|
||||||
|
if (participantClass != 0)
|
||||||
|
{
|
||||||
|
var participant = new Participant
|
||||||
|
{
|
||||||
|
UserId = user.Id,
|
||||||
|
ParticipantClass = participantClass
|
||||||
|
};
|
||||||
|
|
||||||
|
_participantRepository.Insert(participant);
|
||||||
|
}
|
||||||
|
|
||||||
await CurrentUnitOfWork.SaveChangesAsync();
|
await CurrentUnitOfWork.SaveChangesAsync();
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
using Abp.Domain.Entities;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using SystemKonkursow.Authorization.Users;
|
||||||
|
|
||||||
|
namespace SystemKonkursow.Domain
|
||||||
|
{
|
||||||
|
[Table("Participants")]
|
||||||
|
public class Participant : Entity<int>
|
||||||
|
{
|
||||||
|
public long UserId { get; set; }
|
||||||
|
|
||||||
|
public int ParticipantClass { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey(nameof(UserId))]
|
||||||
|
public virtual User User { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -3,11 +3,13 @@ using Abp.Authorization.Users;
|
|||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using SystemKonkursow.Authorization;
|
using SystemKonkursow.Authorization;
|
||||||
using SystemKonkursow.Authorization.Roles;
|
using SystemKonkursow.Authorization.Roles;
|
||||||
using SystemKonkursow.Authorization.Users;
|
using SystemKonkursow.Authorization.Users;
|
||||||
|
using SystemKonkursow.Domain;
|
||||||
|
|
||||||
namespace SystemKonkursow.EntityFrameworkCore.Seed
|
namespace SystemKonkursow.EntityFrameworkCore.Seed
|
||||||
{
|
{
|
||||||
@ -30,14 +32,14 @@ namespace SystemKonkursow.EntityFrameworkCore.Seed
|
|||||||
//list permissions
|
//list permissions
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateUser(new List<Role> { organizerRole }, "Jan", "Kowalski", "organizator", "organizator@example.com");
|
CreateUser(new List<Role> { organizerRole }, "Jan", "Kowalski", "organizator", "organizator@example.com", false);
|
||||||
|
|
||||||
Role participantRole = CreateRole(StaticRoleNames.Host.Participant, new List<string> {
|
Role participantRole = CreateRole(StaticRoleNames.Host.Participant, new List<string> {
|
||||||
PermissionNames.Pages_Solve_Competition
|
PermissionNames.Pages_Solve_Competition
|
||||||
//list permissions
|
//list permissions
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateUser(new List<Role> { participantRole }, "Jerzy", "Nowak", "uczestnik", "uczestnik@example.com");
|
CreateUser(new List<Role> { participantRole }, "Jerzy", "Nowak", "uczestnik", "uczestnik@example.com", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Role CreateRole(string roleName, IList<string> permissionList)
|
private Role CreateRole(string roleName, IList<string> permissionList)
|
||||||
@ -63,8 +65,10 @@ namespace SystemKonkursow.EntityFrameworkCore.Seed
|
|||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateUser(IEnumerable<Role> roles, string name, string surname, string userName, string emailAddress)
|
private void CreateUser(IEnumerable<Role> roles, string name, string surname, string userName, string emailAddress, bool isParticipant)
|
||||||
{
|
{
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
var user = _context.Users.IgnoreQueryFilters()
|
var user = _context.Users.IgnoreQueryFilters()
|
||||||
.FirstOrDefault(u => u.TenantId == 1 && u.UserName == userName);
|
.FirstOrDefault(u => u.TenantId == 1 && u.UserName == userName);
|
||||||
if (null == user)
|
if (null == user)
|
||||||
@ -86,6 +90,18 @@ namespace SystemKonkursow.EntityFrameworkCore.Seed
|
|||||||
_context.Users.Add(user);
|
_context.Users.Add(user);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
if (isParticipant)
|
||||||
|
{
|
||||||
|
var participant = new Participant()
|
||||||
|
{
|
||||||
|
UserId = user.Id,
|
||||||
|
ParticipantClass = rnd.Next(1, 9)
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Participants.Add(participant);
|
||||||
|
_context.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
// Assign role to user
|
// Assign role to user
|
||||||
foreach (var role in roles)
|
foreach (var role in roles)
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,8 @@ namespace SystemKonkursow.EntityFrameworkCore
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DbSet<Domain.Participant> Participants { get; set; }
|
||||||
|
|
||||||
public DbSet<Domain.CompetitionCategory> CompetitionCategories { get; set; }
|
public DbSet<Domain.CompetitionCategory> CompetitionCategories { get; set; }
|
||||||
|
|
||||||
public DbSet<Domain.Category> Categories { get; set; }
|
public DbSet<Domain.Category> Categories { get; set; }
|
||||||
|
@ -1081,6 +1081,23 @@ namespace SystemKonkursow.Migrations
|
|||||||
b.ToTable("CompetitionCategories");
|
b.ToTable("CompetitionCategories");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SystemKonkursow.Domain.Participant", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<int>("ParticipantClass");
|
||||||
|
|
||||||
|
b.Property<long>("UserId");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Participants");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SystemKonkursow.MultiTenancy.Tenant", b =>
|
modelBuilder.Entity("SystemKonkursow.MultiTenancy.Tenant", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -1302,6 +1319,14 @@ namespace SystemKonkursow.Migrations
|
|||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("SystemKonkursow.Domain.Participant", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("SystemKonkursow.Authorization.Users.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SystemKonkursow.MultiTenancy.Tenant", b =>
|
modelBuilder.Entity("SystemKonkursow.MultiTenancy.Tenant", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("SystemKonkursow.Authorization.Users.User", "CreatorUser")
|
b.HasOne("SystemKonkursow.Authorization.Users.User", "CreatorUser")
|
||||||
|
@ -25,4 +25,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
|
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -141,6 +141,8 @@ namespace SystemKonkursow.Controllers
|
|||||||
externalUser.EmailAddress,
|
externalUser.EmailAddress,
|
||||||
externalUser.EmailAddress,
|
externalUser.EmailAddress,
|
||||||
Authorization.Users.User.CreateRandomPassword(),
|
Authorization.Users.User.CreateRandomPassword(),
|
||||||
|
"Organizer",
|
||||||
|
0,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user