Exemplo n.º 1
0
        public async Task <bool> ActivateAccount(string code)
        {
            User user = await _context.Users.SingleOrDefaultAsync(u => u.AcrivationCode == code);

            if (user == null)
            {
                return(false);
            }
            else
            {
                user.IsActive       = true;
                user.AcrivationCode = GeneratorName.GenerateGUID();

                try
                {
                    _context.Users.Update(user);
                    _context.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public void EditProfile(string email, EditUserProfileViewModel profile)
        {
            if (profile.UserAvatar != null)
            {
                string ImagePath = "";
                if (profile.AvatarName != "default.png")
                {
                    ImagePath = Path.Combine(_environment.WebRootPath, "Images/UserAvatar", profile.AvatarName);
                    if (File.Exists(ImagePath))
                    {
                        File.Delete(ImagePath);
                    }
                }
                profile.AvatarName = GeneratorName.GenerateGUID() + Path.GetExtension(profile.UserAvatar.FileName);
                ImagePath          = Path.Combine(_environment.WebRootPath, "Images/UserAvatar", profile.AvatarName);

                using (var stream = new FileStream(ImagePath, FileMode.Create))
                {
                    profile.UserAvatar.CopyTo(stream);
                }
            }
            var user = GetUserByEmail(email);

            user.FirstName  = profile.FirstName;
            user.LastName   = profile.LastName;
            user.Mobile     = profile.Mobile;
            user.UserAvatar = profile.AvatarName;

            UpdateUser(user);
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 37;
         hash = hash * 23 + GeneratorName.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 4
0
        protected override IEnumerable <Command> OnAlter(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            var otherGenerator = FindOtherChecked(targetMetadata.MetadataGenerators.GeneratorsByName, GeneratorName, "role");

            if (EquatableHelper.PropertiesEqual(this, otherGenerator, EquatableProperties, nameof(GeneratorIncrement)))
            {
                yield return(new Command()
                             .Append($"ALTER SEQUENCE {GeneratorName.AsSqlIndentifier()} INCREMENT BY {GeneratorIncrement}"));
            }
            else
            {
                throw new NotSupportedOnFirebirdException($"Altering sequence is not supported ({GeneratorName}).");
            }
        }
Exemplo n.º 5
0
        protected override IEnumerable <Command> OnCreate(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
        {
            var command = new Command();

            command.Append($"CREATE SEQUENCE {GeneratorName.AsSqlIndentifier()}");
            if (context.Settings.TargetVersion.AtLeast30())
            {
                if (InitialValue != 0)
                {
                    command.Append($" START WITH {InitialValue}");
                }
            }
            yield return(command);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Register(AccountViewModel register)
        {
            if (!ModelState.IsValid)
            {
                return(View(register));
            }

            if (await _UserService.IsExistMobileAsync(register.Mobile))
            {
                ModelState.TryAddModelError("Mobile", "موبایل وارد شده تکراری می باشد");
                return(View(register));
            }

            if (_UserService.IsExistEmail(FixedText.FixedEmail(register.Email)))
            {
                ModelState.TryAddModelError("Email", "ایمیل وارد شده تکراری می باشد");
                return(View(register));
            }

            User user = new User()
            {
                FirstName      = register.FirstName,
                LastName       = register.LastName,
                Mobile         = register.Mobile,
                Email          = FixedText.FixedEmail(register.Email),
                IdDelete       = false,
                AcrivationCode = GeneratorName.GenerateGUID(),
                IsActive       = false,
                Password       = PasswordHelper.EncodePasswordMd5(register.Password),
                UserAvatar     = "default.png",
                CreateDate     = DateTime.Now
            };
            await _UserService.AddUserAsync(user);


            #region Sending Activation Email

            string body = _renderViewService.RenderToStringAsync("_ActiveEmail", user);
            SendEmail.Send(user.Email, "فعال سازی حساب کاربری در بافر شاپ", body);

            #endregion

            return(View("SuccessRegister", model: user));
        }
Exemplo n.º 7
0
 protected override IEnumerable <Command> OnDrop(IMetadata sourceMetadata, IMetadata targetMetadata, IComparerContext context)
 {
     yield return(new Command()
                  .Append($"DROP SEQUENCE {GeneratorName.AsSqlIndentifier()}"));
 }