upd Authentification
This commit is contained in:
@@ -32,7 +32,6 @@ namespace SvetoforVKBot.Models.Commands.Registration
|
||||
var ids = new long[] { chatId };
|
||||
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
user.fio = update.@object.message.text.Trim();
|
||||
user.tag = "Подписчик - Регистрация - ДР - Год";
|
||||
db.SaveChanges();
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using SvetoforVKBot.Models.Updates;
|
||||
using VkNet;
|
||||
using VkNet.Enums.SafetyEnums;
|
||||
using VkNet.Model.Keyboard;
|
||||
using VkNet.Model.RequestParams;
|
||||
using System.Linq;
|
||||
using SvetoforVKBot.Services;
|
||||
|
||||
namespace SvetoforVKBot.Models.Commands.Registration
|
||||
{
|
||||
public class GetLoginCommand
|
||||
{
|
||||
public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
|
||||
{
|
||||
var chatId = update.@object.message.from_id;
|
||||
MessagesSendParams @params = new MessagesSendParams();
|
||||
var keyboardBuilder = new KeyboardBuilder().Clear();
|
||||
|
||||
try
|
||||
{
|
||||
if (update.@object.message.text.Length > 0 && update.@object.message.text.Length <= 50)
|
||||
{
|
||||
var ids = new long[] { chatId };
|
||||
string login = update.@object.message.text.Trim();
|
||||
string message = "";
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
string pincode = PasswordService.GeneratePassword();
|
||||
string hash = PasswordService.CreateMD5(pincode + chatId.ToString());
|
||||
message = $"Ваш код подтверждения: {pincode}";
|
||||
|
||||
|
||||
keyboardBuilder
|
||||
.AddButton("Отменить", "startPL", KeyboardButtonColor.Default);
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.Message = "На Вашу корпоративную почту отправлено письмо с кодом подтверждения.\n" +
|
||||
"Введите код в ответ на данное сообщение, чтобы завершить авторизацию.";
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
|
||||
user.login = login;
|
||||
user.password = hash;
|
||||
user.tag = "Подписчик - Регистрация - Код";
|
||||
db.SaveChanges();
|
||||
|
||||
EmailService emailService = new EmailService();
|
||||
emailService.SendEmailAsync($"{login}@vyatsu.ru", "Код подтверждения", message);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@params.Message = "Данные введены некорректно 😕 Напишите, пожалуйста, текст длиной до 50 символов.";
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
@params.Message = "‼Ошибка в GetFIOCommand: " + ee.Message;
|
||||
@params.Attachments = null;
|
||||
@params.Keyboard = null;
|
||||
@params.UserId = 59111081;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
|
||||
public int GetRandomId()
|
||||
{
|
||||
var intBytes = new byte[4];
|
||||
|
||||
Rng.GetBytes(intBytes);
|
||||
|
||||
return BitConverter.ToInt32(intBytes, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
108
SvetoforVKBot/Models/Commands/Registration/GetPincodeCommand.cs
Normal file
108
SvetoforVKBot/Models/Commands/Registration/GetPincodeCommand.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using SvetoforVKBot.Models.Updates;
|
||||
using VkNet;
|
||||
using VkNet.Enums.SafetyEnums;
|
||||
using VkNet.Model.Keyboard;
|
||||
using VkNet.Model.RequestParams;
|
||||
using System.Linq;
|
||||
using SvetoforVKBot.Services;
|
||||
using SvetoforVKBot.Models.Commands.LK;
|
||||
|
||||
namespace SvetoforVKBot.Models.Commands.Registration
|
||||
{
|
||||
public class GetPincodeCommand
|
||||
{
|
||||
public void Execute(RootObject update, VkApi client, SvetoforVKBot.Data.SvetoforVKBotEntities db)
|
||||
{
|
||||
var chatId = update.@object.message.from_id;
|
||||
MessagesSendParams @params = new MessagesSendParams();
|
||||
var keyboardBuilder = new KeyboardBuilder().Clear();
|
||||
|
||||
try
|
||||
{
|
||||
if (update.@object.message.text.Length > 0 && update.@object.message.text.Length <= 50)
|
||||
{
|
||||
var ids = new long[] { chatId };
|
||||
string pincode = update.@object.message.text.Trim();
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
|
||||
string hashCheck = PasswordService.CreateMD5(pincode + chatId.ToString());
|
||||
|
||||
if (user.password.Equals(hashCheck))
|
||||
{
|
||||
user.isAuthorized = 1;
|
||||
user.tag = "Подписчик - Регистрация - Пол";
|
||||
db.SaveChanges();
|
||||
|
||||
if (user.reg == 1)
|
||||
{
|
||||
ShowLKCommand showLK = new ShowLKCommand();
|
||||
showLK.Execute(update, client, db);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
keyboardBuilder
|
||||
.AddButton("М", "selectGender-1", KeyboardButtonColor.Primary)
|
||||
.AddButton("Ж", "selectGender-2", KeyboardButtonColor.Primary)
|
||||
.AddLine()
|
||||
.AddButton("Отменить", "startPL", KeyboardButtonColor.Default);
|
||||
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.Message = //1 шаг из 4.
|
||||
"✅ Авторизация прошла успешно.\n" +
|
||||
"Выберите на клавиатуре внизу или напишите пол в формате \"М\" или \"Ж\"";
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
keyboardBuilder
|
||||
.AddButton("Отменить", "startPL", KeyboardButtonColor.Default);
|
||||
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.Message = "Вы ввели неверный код подтверждения. Попробуйте ещё раз.";
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@params.Message = "Данные введены некорректно 😕 Напишите, пожалуйста, текст длиной до 50 символов.";
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
@params.Message = "‼Ошибка в GetFIOCommand: " + ee.Message;
|
||||
@params.Attachments = null;
|
||||
@params.Keyboard = null;
|
||||
@params.UserId = 59111081;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
|
||||
public int GetRandomId()
|
||||
{
|
||||
var intBytes = new byte[4];
|
||||
|
||||
Rng.GetBytes(intBytes);
|
||||
|
||||
return BitConverter.ToInt32(intBytes, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,44 +34,11 @@ namespace SvetoforVKBot.Models.Commands.Registration
|
||||
{
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
|
||||
List<MediaAttachment> listDoc = new List<MediaAttachment>()
|
||||
user.tag = "Подписчик - Регистрация - Авторизация";
|
||||
db.SaveChanges();
|
||||
|
||||
if (user.isAuthorized == 0)
|
||||
{
|
||||
new Document() { Id = 602601883, OwnerId = 59111081 } //59111081_600676073
|
||||
};
|
||||
|
||||
if (user.agree == 0)
|
||||
{
|
||||
switch (user.child)
|
||||
{
|
||||
case 0:
|
||||
@params.Message = "Вам уже исполнилось 18 лет? Исходя из возраста, мы сформируем для Вас подходящий документ " +
|
||||
"согласия на обработку персональных данных.\n\n" +
|
||||
"Нажмите кнопку на специальной клавиатуре👇";
|
||||
|
||||
keyboardBuilder
|
||||
.AddButton("Да", "selectChildAge-2", KeyboardButtonColor.Positive)
|
||||
.AddButton("Нет", "selectChildAge-1", KeyboardButtonColor.Negative)
|
||||
.AddLine()
|
||||
.AddButton("Назад", "startPL", KeyboardButtonColor.Default);
|
||||
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
return;
|
||||
|
||||
default:
|
||||
SelectAgreementCommand selectAgreement = new SelectAgreementCommand();
|
||||
selectAgreement.ExecutePL(update, client, db);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
user.tag = "Подписчик - Регистрация - Пол";
|
||||
db.SaveChanges();
|
||||
|
||||
keyboardBuilder
|
||||
.AddButton("М", "selectGender-1", KeyboardButtonColor.Primary)
|
||||
.AddButton("Ж", "selectGender-2", KeyboardButtonColor.Primary)
|
||||
@@ -81,10 +48,12 @@ namespace SvetoforVKBot.Models.Commands.Registration
|
||||
@params.Keyboard = keyboardBuilder.Build();
|
||||
@params.UserId = chatId;
|
||||
@params.Message = //1 шаг из 4.
|
||||
"Выберите на клавиатуре внизу или напишите пол в формате \"М\" или \"Ж\"";
|
||||
"Для продолжения необходимо авторизоваться. Введите Ваш логин, ипользуемый на портале ВятГУ.\n" +
|
||||
"Например, stud0000";
|
||||
@params.RandomId = GetRandomId();
|
||||
client.Messages.SendAsync(@params);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SvetoforVKBot.Models.Commands.Registration
|
||||
{
|
||||
var user = db.Users.Single(usr => usr.chatId == chatId);
|
||||
user.tag = "Регистрация - Возраст";
|
||||
user.fio = user.firstName + " " + user.lastName;
|
||||
//user.fio = user.firstName + " " + user.lastName;
|
||||
db.SaveChanges();
|
||||
|
||||
@params.Message = "2 шаг из 4. Напиши возраст одним числом, например, 19. \n";
|
||||
|
||||
Reference in New Issue
Block a user