Skip to content

Commit

Permalink
pUSH QILGANDA NEGADIR FAYLLAR SAQLANMAYABDI
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 10, 2023
1 parent 32f72ee commit fdc1984
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 13 deletions.
40 changes: 36 additions & 4 deletions Imtihon_Update/DispatchEmail.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading.Tasks;

using Imtihon_Update.Interfaces;
namespace Imtihon_Update
{
internal class DispatchEmail
public static class DispatchEmail

{
}
}
//ismiz
/*var name = Console.ReadLine();
Console.WriteLine("email");
var email = Console.ReadLine();
Console.WriteLine("enter passaword");
var pass = Console.ReadLine();
var Email = new EmailService(email, pass);
Email.SendEmail(email, name);*/

public static bool SendEmail(string receiverEmail, string name)
{
try
{
var CredentialAddress = "[email protected]";
var CredentialPassword = "bypucbhumkeghlab";

var mail = new MailMessage(CredentialAddress, receiverEmail);
mail.Subject = "Siz muvaffaqiyatli registratsiyadan o'tdingiz";
mail.Body = "Hurmatli {{User}}, siz sistemadan muvaffaqiyatli o'tdingiz Tabriklaymiz".Replace("{{User}}", name);
var smtpClient = new SmtpClient("smtp.gmail.com", 587); //
smtpClient.Credentials = new NetworkCredential(CredentialAddress, CredentialPassword);
smtpClient.EnableSsl = true;

smtpClient.Send(mail);
return true;
}
catch { return false; }
}
}

}
2 changes: 1 addition & 1 deletion Imtihon_Update/Imtihon_Update.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
15 changes: 14 additions & 1 deletion Imtihon_Update/Interfaces/IRegistrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@

namespace Imtihon_Update.Interfaces
{
internal interface RegistrationService
public interface IRegistrationservice
{

public bool ChekName(string ism, string familya, string sharif) { return true; }


public bool CheckEmailAddress(string email) { return true; }

public string GenerateUserName(string ism, string sharf) { return ""; }

public bool Add(string name, string familya, string sharif, string email, ref string username) { return true; } // - parameterlari - ism, sharif, email address va ixtiyoriy username

public void Register(string ism, string familya, string sharif, string email, string username) { } // - parameterlari - ism, sharif, email address va ixtiyoriy username

public void Display() { }
}
}
9 changes: 8 additions & 1 deletion Imtihon_Update/Interfaces/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

namespace Imtihon_Update.Interfaces
{
internal interface IUser
public interface IUser
{
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Username { get; set; }
public bool IsActived { get; set; }

}
}
54 changes: 52 additions & 2 deletions Imtihon_Update/Program.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using Imtihon_Update;
using Imtihon_Update.Interfaces;
var Registrationservice = new RegistrationService();
bool exit = true;
while (exit)
{
Console.WriteLine("Dastruni tuxtatish uchun [e] ni bosing");
Console.WriteLine("Ruyhatdan utish uchun [r] va bizning a'zolarimizni kurish uchun[d] ni bosing");
var check = Console.ReadLine().ToLower();
switch (check)
{
case "e":
Console.Clear();
exit = false;
break;
case "r":
Console.Clear();
Console.WriteLine("Enter Name ");
string ism = Console.ReadLine();
Console.WriteLine("Enter FirstName: ");
string familya = Console.ReadLine();
Console.WriteLine("Enter Middle Name: ");
string sharif = Console.ReadLine();
Console.WriteLine("Enter email Address: ");
string email = Console.ReadLine();
Console.WriteLine("Enter a username");
string username = Console.ReadLine();
Registrationservice.Register(ism, familya, sharif, email, username);
//Registrationservice.Register(ism, familya, sharif, email, username);
break;
case "d":
Console.Clear();
Registrationservice.Display();
break;
default:
Console.WriteLine("Bunday komanda yuq dasturdan xato foydalandingiz");
break;
}

}












145 changes: 143 additions & 2 deletions Imtihon_Update/Registrationservice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,152 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using Imtihon_Update.Interfaces;
namespace Imtihon_Update
{
internal class Registrationservice
public class RegistrationService: IRegistrationservice
{
// - agar ism, sharif, email address valid bo’lmasa ekranga qaysi biri invalid ekanligi chiqarilsin
List<string> list;
//Users kolleksiyasi - foydalanuvchilar ma’lumotlarini saqlab turuvchi User tipidagi kolleksiya bo’lsin
private List<User> Users;

//Konstructor
public RegistrationService()
{
Users = new List<User>();

list = new List<string>();
}


//- Users kolleksiyasi - foydalanuvchilar ma’lumotlarini saqlab turuvchi User tipidagi kollesiya bo’lsin va unga shu tip ichidangina murojaat qilish mumkin bo’lsin

//- CheckName - ism / familya / sha’rif ni tekshiradi, valid bo’lsa true, invalid bo’lsa false qaytaradi
public bool ChekName(string ism, string familya, string sharif)
{
var check = true;
const string regexName = "^[a-zA-Z'-]+$";
Regex regex = new Regex(regexName);
if (!regex.IsMatch(ism))
{
list.Add("Ism xato kiritildi");
check = false;
}
if (!regex.IsMatch(familya))
{
list.Add("Familya xato kiritildi");
check = false;
}
if (!regex.IsMatch(sharif))
{
check = false;
list.Add("Sharifingiz notugri kiritildi");
}
return check;
}

//- CheckEmailAddress - email manzilini tekshiradi, valid bo’lsa true, invalid bo’lsa false qaytaradi
public bool CheckEmailAddress(string email)
{
var check = true;
const string regexEmail = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
Regex regex = new Regex(regexEmail);
if (!regex.IsMatch(email) || string.IsNullOrWhiteSpace(email))
{
check = false;
list.Add("Email notugri kiritildi");
}
return check;
}

//- GenerateUserName methodi - unique username generate qiladi
public string GenerateUserName(string ism, string sharf)
{
var rd = new Random();
return $"{ism.ToLower()}_{sharf.ToLower()}{rd.Next(10, 100)}";
}



private bool Add(string name, string familya, string sharif, string email, ref string username) // - parameterlari - ism, sharif, email address va ixtiyoriy username
{
// - methodda ism, sharif, email address valid ekanligini tekshirilsin
// - username invalid yoki unique bo’lmasa GenerateUsername orqali yangi generate qilinsin
// - foydalanuvchi hamma ma’lumotlarni valid bolsa foydalanuvchilar kolleksiyasiga qo’shsin va true qaytarsin aks holda false
// - method faqat tip ichidangina murojaat qilish mumkin bo’lsin
bool checkname = true;
bool checkemail = true;
if (!ChekName(name, familya, sharif))
{
checkname = false;
}
if (!CheckEmailAddress(email))
{
checkemail = false;
}

foreach (var item in Users)
{
if (item.Username.Equals(username, StringComparison.OrdinalIgnoreCase))
{
username = GenerateUserName(name, familya);
}


}
var returntype = checkemail == true && checkname == true ? true : false;
return returntype;
}


public void Register(string ism, string familya, string sharif, string email, string username) // - parameterlari - ism, sharif, email address va ixtiyoriy username
{
// - Register methodi
// - parameterlari - ism, sharif, email address va ixtiyoriy username
// - Add methodi orqali foydalanuvchini qo’shsin
// - agar Add methodi true qaytarsa foydalanuvchiga SendEmail orqali email jo’natsin
// - agar SendEmail true qaytarsa foydalanuvchidagi aktiv ekanligini bildiruvchi property ga true qiymat yozilsin
var userchecker = Add(ism, familya, sharif, email, ref username);
if (userchecker)
{
var user = new User(ism, familya, sharif, email, username);
if (DispatchEmail.SendEmail(email, username) == true)
{
user.IsActived = true;
}
else
{
Console.WriteLine("Internat muommosi tufayli message junatilmadi keyinroq urinib kuring yoki chet elga chiqib junating ");
}
Users.Add(user);
}
else
{
foreach (var item in list)
{
Console.WriteLine(item);
}
list.Clear();
}
}

public void Display()
{

if (Users.Count > 0)
{
foreach (var user in Users)
{
Console.WriteLine(user);
}
}
else
{
Console.WriteLine("Bizda foydalanuvchilar mavjud emas sizga uz hizmatimizni taklif etamiz foydalanish uchun ruyhattan uting");
}
}
}
}
28 changes: 26 additions & 2 deletions Imtihon_Update/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Imtihon_Update.Interfaces;
namespace Imtihon_Update
{
internal class User
public class User:IUser
{
//User modeli - foydalanuvchi ismi, familyasi, sharifi, email addresi, username va aktiv foydalanuvchi ekanligi haqidagi ma’lumotlarni saqlovchi model
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Username { get; set; }
public bool IsActived { get; set; }

public User() { }

public User(string name, string firstName, string lastName, string email, string username)
{
Name = name;
FirstName = firstName;
LastName = lastName;
Email = email;
Username = username;
}

public override string ToString()
{
return $"Name: {Name.PadLeft(20)}\nFirstName: {FirstName.PadLeft(20)}\n" + $"EmailAddress: {Email.PadLeft(30)}\nUserName: {Username.PadLeft(15)}\n\n";

}
}
}

0 comments on commit fdc1984

Please sign in to comment.