Пример #1
0
        //Sign up - save the sign up date to the database
        public void AddUserAccount(UserModel user, AddressModel address)
        {
            using (ECommerceEntities db = new ECommerceEntities())
            {
                try
                {
                    PasswordManager PM = new PasswordManager();
                    t_Users US = new t_Users();
                    US.UserName = user.Username;
                    US.Password = PM.Encrypt(user.Password);
                    US.FirstName = user.FirstName;
                    US.LastName = user.LastName;
                    US.Email = user.Email;
                    US.Gender = user.Gender;
                    db.t_Users.Add(US);
                    //db.SaveChanges();
                    var result = db.Database.ExecuteSqlCommand("exec upSaveUser @UserName, @Password, @Email, @FirstName, @Surname, @Gender", new SqlParameter("UserName", US.UserName),
                        new SqlParameter("Password", US.Password), new SqlParameter("Email", US.Email), new SqlParameter("FirstName", US.FirstName), new SqlParameter("Surname", US.LastName),
                        new SqlParameter("Gender", US.Gender));

                    //AddressModel AD = new AddressModel();
                    t_UsersAddress TAD = new t_UsersAddress();
                    TAD.AddressNumber = address.AddressNumber;
                    TAD.AddressPostalCode = address.AddressPostalCode;
                    TAD.AddressRoadName = address.AddressRoadName;
                    TAD.AddressSuburb = address.AddressSuburb;

                    TAD.UID = US.UID;
                    TAD.AddressCity = address.AddressCity;
                    db.t_UsersAddress.Add(TAD);
                    //db.SaveChanges();

                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Пример #2
0
        public ActionResult SignUp(UserModel USV, AddressModel AM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UserManagerFK UM = new UserManagerFK();

                    if (!UM.IsLoginNameExist(USV.Username) || !UM.IsEmailExist(USV.Email))
                    {
                        UM.AddUserAccount(USV, AM);
                        FormsAuthentication.SetAuthCookie(USV.FirstName, false);
                        return RedirectToAction("Welcome", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Username already taken.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return View();
        }
Пример #3
-1
        public ActionResult ForgotPassword(ForgotPasswordViewModelMyOwn model)
        {
            if (ModelState.IsValid)
            {
                ResetPassword RP = new ResetPassword();
                UserModel UM = new UserModel();
                UserManagerFK UMF = new UserManagerFK();
                string email = UMF.GetUserEmail(model.UserName);

                if (email == null)
                {

                    return View("ForgotPasswordConfirmation");
                }

                Guid EMailCode = Guid.NewGuid();
                var callbackUrl = Url.Action("ResetPassword", "UserAccount", new { userId = email, code = EMailCode }, protocol: Request.Url.Scheme);

                UMF.AddResetPasswordDetails(EMailCode, email, "Y");

                //SmtpClient SmtpClient = new SmtpClient("smtp.gmail.com");
                //MailAddressCollection MailAddressCollection = new MailAddressCollection();
                //MailMessage message = new MailMessage();
                //message.From = new MailAddress("*****@*****.**", "Faheem Kathrada");
                //message.Body = "Please reset your password by clicking < a href =\"" + callbackUrl + "\">here</a>";
                //message.Subject = "Nexidia Log Files";
                //message.To.Add("*****@*****.**");

                //SmtpClient.Port = 587;
                //SmtpClient.EnableSsl = true;
                //SmtpClient.Send(message);
                //message.Dispose();

                var client = new SmtpClient("smtp.gmail.com", 587)
                {
                    Credentials = new NetworkCredential("*****@*****.**", "8September@008"),
                    EnableSsl = true
                };
                client.Send("*****@*****.**", "*****@*****.**", "Password Reset", "Please reset your password by clicking < a href =\"" + callbackUrl + "\">here</a>");

                return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            return View(model);
        }