-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
c9af020
commit 3599c5b
Showing
17 changed files
with
392 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using N23_HT24.Models; | ||
|
||
namespace N23_HT24.Services | ||
{ | ||
public interface IUserCredentialsService | ||
{ | ||
//IUserCredentialsService dan foydalaning | ||
//unda quyidagi methodlar bo'lsin | ||
|
||
//- Add ( userId, password ) -password ni strong ekanligini regex bilan tekshirsin ( 8 <= simvol, 1 <= katta harf, 1 <= son ), valid bo'lsa qo'shsin va credential ni qaytarsin bo'lmasa exception | ||
//- GetByUserId ( userId ) -user Id bo'yicha credential ni topib qaytarsin, bo'lmasa null | ||
public UserCredentials Add(Guid userId,string password); | ||
public UserCredentials GetByUserId(Guid userId); | ||
|
||
} | ||
} |
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,33 @@ | ||
using N23_HT24.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N23_HT24.Services | ||
{ | ||
public interface IUserService | ||
{ | ||
//IUserService dan foydalaning | ||
//unda quyidagi methodlar bo'lsin | ||
|
||
//- Get ( pageSize, pageToken ) -userlarni pagination bian qaytarsin | ||
//- Search ( searchKeyword, pageSize, pageToken ) -userlar ni kalit so'z bo'yicha qidirib pagination bilan qaytarsin | ||
//- Filter ( userFilterModel ) -userlarni filter qilib pagination bilan qaytarsin | ||
//- Add ( firstname, lastname, emailAddress ) -email address unique bo'lsa user ni qo'shsin va qaytarsin, bo'lmasa exception | ||
//- Update ( user ) -userlar ichidan berilgan user borligini topib, update qilsin va qaytarsin, bo'lmasa exception | ||
//- Delete ( id ) -userlar ichidan berilgan id bo'yicha user borligini topib IsDeleted true qilsin, bo'lmasa exception | ||
|
||
|
||
public List<User>? Get(int pagesize, int pagetoken); | ||
public List<User> Search(string searchkeyword, int pagesize, int pagetoken); | ||
public List<User> Filter(UserFilterModel userFilterModel); | ||
public User Add(string firstname, string lastname, string emailaddress); | ||
public User Update(User user); | ||
public void Delete(Guid id); | ||
|
||
|
||
|
||
} | ||
} |
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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N23_HT24.Models | ||
{ | ||
public abstract class FilterModel | ||
{ | ||
//FilterModel abstrakt modeldan foydalaning ( pageSize, pageToken ) | ||
public int PageSize { get; set; } | ||
public int PageToken { get; set; } | ||
|
||
|
||
} | ||
} |
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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N23_HT24.Models | ||
{ | ||
public class User | ||
{ | ||
//User modelidan foydalaning ( id, firstname, lastname, emailAddress, isDeleted ) | ||
public Guid Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string LastName { get; set; } | ||
public string EmailAddress { get; set; } | ||
public bool isDeleted { get; set; } | ||
|
||
public User(string firstName, string lastName, string emailAddress) | ||
{ | ||
Id = Guid.NewGuid(); | ||
FirstName = firstName; | ||
LastName = lastName; | ||
EmailAddress = emailAddress; | ||
this.isDeleted = false; | ||
} | ||
} | ||
} |
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,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N23_HT24.Models | ||
{ | ||
public class UserCredentials | ||
{ | ||
//UserCredentials modelidan foydalaning ( id, password, userId ) | ||
public Guid Id { get; set; } | ||
public string password { get; set; } | ||
public Guid UserId { get; set; } | ||
|
||
public UserCredentials(string password, Guid userId) | ||
{ | ||
Id = Guid.NewGuid(); | ||
this.password = password; | ||
UserId = userId; | ||
} | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace N23_HT24.Models | ||
{ | ||
public class UserFilterModel:FilterModel | ||
{ | ||
//UserFilterModel dan foydalaning ( firstname?, lastname? ) u FilterModel dan inheritance olgan bo'lsin | ||
public string? FirstName { get; set; } | ||
public string? LastName { get; set;} | ||
} | ||
} |
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,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,38 @@ | ||
using System.Net; | ||
using N23_HT24.Services; | ||
|
||
//PS : UserCredentialsService da parameterized konstruktor bo'lsin, u orqali | ||
//IUserService va IUserCredentialsService implementatsiya qilgan tipdan object berib, fieldga saqlanadigan bo'lsin | ||
//( biz buni AccountService misolida ko'rganmiz ) | ||
|
||
//- dasturda UserCredentialsService dan object yarating | ||
//- bir nechta userlar qo'shing va natijasini ekranga chiqaring | ||
//- konsoldan keyword kiritib, userlar ni search qilib ekranga chiqaring | ||
var userService = new UserService(); | ||
var UserCredentials = new UserCredentialsService(); | ||
var register = new RegistrationService(userService,UserCredentials); | ||
|
||
|
||
register.Register("John", "Doe", "[email protected]", "securepassword123"); | ||
register.Register("Jane", "Smith", "[email protected]", "strongpassword456"); | ||
register.Register("Michael", "Johnson", "[email protected]", "mypassword789"); | ||
register.Register("Emily", "Brown", "[email protected]", "safepassword2023"); | ||
register.Register("William", "Jones", "[email protected]", "complexpass321"); | ||
register.Register("Olivia", "Garcia", "[email protected]", "password987654"); | ||
register.Register("James", "Miller", "[email protected]", "myp@ssw0rd"); | ||
register.Register("Sophia", "Davis", "[email protected]", "newpassw0rd"); | ||
register.Register("Benjamin", "Martinez", "[email protected]", "securepass123"); | ||
register.Register("Ava", "Rodriguez", "[email protected]", "password2023"); | ||
register.Register("Liam", "Lopez", "[email protected]", "strongpass789"); | ||
register.Register("Emma", "Hernandez", "[email protected]", "safe123456"); | ||
register.Register("Noah", "Moore", "[email protected]", "password21"); | ||
register.Register("Isabella", "Lee", "[email protected]", "passcode123"); | ||
register.Register("Ethan", "Clark", "[email protected]", "newpassword456"); | ||
register.Register("Mia", "Lewis", "[email protected]", "securepassw0rd"); | ||
register.Register("Aiden", "Walker", "[email protected]", "password987"); | ||
register.Register("Lily", "Hall", "[email protected]", "strongpass2023"); | ||
register.Register("Carter", "Young", "[email protected]", "safe456789"); | ||
register.Register("Grace", "Allen", "[email protected]", "mypassword123"); | ||
|
||
//userService.Get(10,1).ForEach(user => Console.WriteLine($"{user.FirstName} {user.LastName} - {user.EmailAddress}")); | ||
userService.Search("e",10,1).ForEach(user => Console.WriteLine($"{user.FirstName} {user.LastName} - {user.EmailAddress}")); |
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,34 @@ | ||
namespace N23_HT24.Services; | ||
|
||
public class RegistrationService | ||
{ | ||
//RegistrationService dan foydalaning | ||
//unda quyidagi methodlar bo'lsin | ||
|
||
//- Register ( firstName, lastName, emailAddress, password ) -UserService orqali userni UserCredentialsService | ||
//orqali credentialni qo'shsin, hammasi muvaffaqqiyatli bo'lsa true, bo'lmasa false qaytarsin | ||
|
||
|
||
private readonly IUserService _userService; | ||
private readonly IUserCredentialsService _credentialsService; | ||
|
||
public RegistrationService(IUserService userService, IUserCredentialsService credentialsService) | ||
{ | ||
_userService = userService; | ||
_credentialsService = credentialsService; | ||
} | ||
|
||
public bool Register(string firstName, string lastName, string emailAddress, string password) | ||
{ | ||
try | ||
{ | ||
var user = _userService.Add(firstName, lastName, emailAddress); | ||
_credentialsService.Add(user.Id, password); | ||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
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,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using N23_HT24.Models; | ||
|
||
namespace N23_HT24.Services | ||
{ | ||
public class UserCredentialsService:IUserCredentialsService | ||
{ | ||
//IUserCredentialsService dan foydalaning | ||
//unda quyidagi methodlar bo'lsin | ||
//- Add ( userId, password ) -password ni strong ekanligini regex bilan tekshirsin ( 8 <= simvol, 1 <= katta harf, 1 <= son ), valid bo'lsa qo'shsin va credential ni qaytarsin bo'lmasa exception | ||
//- GetByUserId ( userId ) -user Id bo'yicha credential ni topib qaytarsin, bo'lmasa null | ||
private List<UserCredentials> _userCredentials = new List<UserCredentials>(); | ||
|
||
public UserCredentials Add(Guid userId, string password) | ||
{ | ||
if (Regex.IsMatch(password, @"^(?=.*[A-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{8,}$")) | ||
{ | ||
var userCradential = new UserCredentials(password, userId); | ||
_userCredentials.Add(userCradential); | ||
return userCradential; | ||
|
||
} | ||
else | ||
{ | ||
throw new InvalidOperationException("User credentials Invalid"); | ||
} | ||
|
||
} | ||
|
||
public UserCredentials? GetByUserId(Guid userId) | ||
{ | ||
return _userCredentials.Any(user => user.Id == userId) | ||
? _userCredentials.Find(user => user.Id == userId) | ||
: null; | ||
} | ||
} | ||
} |
Oops, something went wrong.