Exemple #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.ConfirmPassword != model.Password)
            {
                ModelState.AddModelError(String.Empty, "Parolalar uyuşmuyor!");
                return(View(model));
            }
            var name = await _userManager.FindByNameAsync(model.UserName);

            if (name != null)
            {
                ModelState.AddModelError(String.Empty, "Bu kullanıcı adı daha önce alınmış.");
                return(View(model));
            }
            var user = new AppIdentityUser
            {
                UserName = model.UserName,
                Email    = model.Email
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                var result2 = await _userManager.AddToRoleAsync(user, "User");

                _gostieContext.Customers.Add(new Customer
                {
                    Identity = user.Id
                });
                _gostieContext.SaveChanges();
                var confirmationCode = _userManager.GenerateEmailConfirmationTokenAsync(user);

                var callBackUrl = Url.Action("ConfirmEmail", "User", new { userID = user.Id, code = confirmationCode.Result });
                /*Email*/
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("Email onayı", "*****@*****.**"));
                message.To.Add(new MailboxAddress("Email onayı", user.Email));
                message.Subject = "Gostie e-mail onayı";
                message.Body    = new TextPart("plain")
                {
                    Text = "Giriş yapabilmek için email onayı gerekmekte. Aşağıdaki linkten yapabilirsiniz;\n " + callBackUrl
                };
                using (var client = new SmtpClient())
                {
                    client.Connect("smtp.gmail.com", 465, true);
                    client.Authenticate("*****@*****.**", "yazilim1998");
                    client.Send(message);
                    client.Disconnect(true);
                }
                /*Email*/
                return(RedirectToAction("Login", "User", new { message = "Kaydınız oluşturulmuştur. Lütfen Mail kutunuzu kontrol edin." }));
            }
            ModelState.AddModelError(String.Empty, "Parolanız bir büyük harf, bir işaret(.,!*) ve bir rakam içermelidir.");
            return(View(model));
        }
        public bool UploadFile(IFormFile file, int id, int who)
        {
            string pathname = "";

            if (who == 0)
            {
                pathname = "products";
            }
            else if (who == 1)
            {
                pathname = "categories";
            }
            else
            {
                pathname = "sliders";
            }
            try
            {
                string fileName = id.ToString() + "_" + DateTime.Now.ToShortDateString() + file.FileName;
                var    path     = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/" + pathname, fileName);
                using (var fileStream = new FileStream(path, FileMode.Create))
                {
                    file.CopyTo(fileStream);
                }
                if (who == 0)
                {
                    _context.Products.Find(id).Picture = fileName;
                }
                else if (who == 1)
                {
                    _context.Categories.Find(id).Picture = fileName;
                }
                else
                {
                    _context.Sliders.Find(id).SliderImage = fileName;
                }
                _context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }