示例#1
0
        public async Task <ServiceResult> RegistrationAsync(RegistrationViewModel model)
        {
            ServiceResult result = new ServiceResult()
            {
                ErrorMessages = new List <string>(),
                Successful    = false
            };

            if (await EmailIsUniq(model.Email))
            {
                if (await LoginIsUniq(model.Login))
                {
                    User user = new User()
                    {
                        ConfirmEmail = false,
                        Email        = model.Email,
                        Login        = model.Login,
                        Firstname    = model.FirstName,
                        LastChanges  = DateTime.Now,
                        Lastname     = model.LastName,
                        Salt         = PasswordManager.GenerateSalt(),
                        Role         = "User"
                    };
                    user.PasswordHash = PasswordManager.GenerateHash(model.Password, PasswordManager.MainSalt + user.Salt);
                    context.Users.Add(user);
                    await context.SaveChangesAsync();

                    Token token = new Token()
                    {
                        GenerationDate = DateTime.Now,
                        UserId         = user.Id,
                        Value          = PasswordManager.GenerateToken(15),
                        Action         = "coem"
                    };
                    context.Tokens.Add(token);
                    await context.SaveChangesAsync();

                    /*await EmailManager.SendMessageAsync(user.Email,
                     *  $"Благодарим за регистрацию." +
                     *  $" Для подтверждения эл. почты перейдите по" +
                     *  $" <a href=\"https://{AppConfig.AppUrl}/Account/ConfirmEmail?token={token.Value}\"> ссылке </a>",
                     *  "Shpilka регистрация");*/
                    string directoryName = AppConfig.UsersPath + "/" + user.Id.ToString();
                    Directory.CreateDirectory(directoryName);
                    result.Successful = true;
                }
                else
                {
                    result.ErrorMessages.Add("Пользователь с таким логином уже зарегистрирован");
                }
            }
            else
            {
                result.ErrorMessages.Add("Пользователь с такой электронной почтой уже зарегистрирован");
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// Создание бота (только телеграм)
        /// </summary>
        /// <param name="model"></param>
        /// <param name="masterId"></param>
        /// <returns></returns>
        public async Task <bool> CreateBotAsync(CreateBotViewModel model, Models.User user)
        {
            if (user.ConfirmEmail && user.BotCount < 3 && (await context.Bots.FirstOrDefaultAsync(b => b.Key == model.Key || b.Name == model.Name)) == null)
            {
                TelegramBot bot = new TelegramBot(model.Name, model.Key)
                {
                    DateOfReg    = DateTime.Now,
                    LastActivity = DateTime.Now,
                    MasterId     = user.Id,
                    IsActive     = true,
                };
                await bot.GetClient();

                Bot bot_ = bot.TakeAsParent();
                context.Bots.Add(bot_);
                user.BotCount++;
                await context.SaveChangesAsync();

                bot.Id = bot_.Id;
                Directory.CreateDirectory(AppConfig.UsersPath + $"/{user.Id}/bots/{bot.Id}/functional");
                bot.PhysicalPath = bot_.PhysicalPath = AppConfig.UsersPath + $"/{bot.MasterId}/bots/{bot_.Id}";
                await bot_.SaveFunctionalAsync(new Functional()
                {
                    BotId            = bot.Id,
                    CommandFunctions = bot.Functions
                });

                await context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }