public ActionResult VerifyRegister(Registration regs, string id)
        {
            ViewBag.code = TempData.Peek("code").ToString();
            string session = (string)System.Web.HttpContext.Current.Session["IDUser"];

            if (id == null)
            {
                return(RedirectToAction("Login", "Main"));
            }
            else if (session == null)
            {
                return(RedirectToAction("Login", "Main"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    using (ASPMVCDB db = new ASPMVCDB())
                    {
                        var obj = db.Registration.Where(model => model.Id.Equals(session)).FirstOrDefault();
                        if (obj != null)
                        {
                            if (obj.VerifyActivationCode == regs.UserActivationCode)
                            {
                                var ObjUpdate = db.Registration.Find(obj.Id);
                                ObjUpdate.UserActivationCode = obj.VerifyActivationCode;
                                db.Entry(ObjUpdate).State    = EntityState.Detached;
                                db.Entry(ObjUpdate).State    = EntityState.Modified;
                                db.SaveChanges();
                                TempData.Remove("code");

                                long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                                Session["TOURING"] = "SIMPLE_TOUR_STARTED_IN" + milliseconds.ToString().Substring(1, 5) + "ERA";
                            }
                            else
                            {
                                ViewBag.Color   = "red";
                                ViewBag.Message = "Wrong Verification Code";
                                return(View());
                            }
                        }
                        else
                        {
                            ViewBag.Color   = "red";
                            ViewBag.Message = "Your ID Is Not Found";
                            return(View());
                        }
                    }
                }
                return(RedirectToRoute("SimpleTour"));
            }
        }
        public ActionResult ChangePassword(Registration regs, string id)
        {
            string session = (string)System.Web.HttpContext.Current.Session["ID"];

            if (id == null)
            {
                return(RedirectToAction("Login", "Main"));
            }
            else if (session == null)
            {
                return(RedirectToAction("Login", "Main"));
            }
            else if (regs.ConfirmPassword != regs.Password)
            {
                long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                return(RedirectToRoute("ChangePassword", new { id = milliseconds }));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    using (ASPMVCDB db = new ASPMVCDB())
                    {
                        var obj = db.Registration.Where(model => model.Id.Equals(session)).FirstOrDefault();
                        if (obj != null)
                        {
                            string encoded   = Encryption(regs.Password);
                            var    ObjUpdate = db.Registration.Find(obj.Id);
                            ObjUpdate.Password        = encoded;
                            ObjUpdate.ConfirmPassword = encoded;
                            db.Entry(ObjUpdate).State = EntityState.Detached;
                            db.Entry(ObjUpdate).State = EntityState.Modified;
                            db.SaveChanges();

                            Session.Clear();
                            Session.Abandon();
                        }
                        else
                        {
                            ViewBag.Color   = "red";
                            ViewBag.Message = "Your ID Is Not Found";
                            return(View());
                        }
                    }
                }
                return(RedirectToAction("Login", "Main"));
            }
        }
        public ActionResult Login(Registration regs)
        {
            string encoded = Encryption(regs.Password);

            if (ModelState.IsValid)
            {
                using (ASPMVCDB db = new ASPMVCDB())
                {
                    //get username dan password dari DB
                    var obj = db.Registration.Where(model => model.Username.Equals(regs.Username) && model.Password.Equals(encoded)).FirstOrDefault();
                    if (obj != null)
                    {
                        if (obj.VerifyActivationCode == obj.UserActivationCode)
                        {
                            /*UPDATE SESSION ISACTIVE JADI 1*/
                            var    ObjUpdate = db.Registration.Find(obj.Id);
                            String isActive  = ObjUpdate.IsActive;
                            ObjUpdate.IsActive        = "1";
                            db.Entry(ObjUpdate).State = EntityState.Detached;
                            db.Entry(ObjUpdate).State = EntityState.Modified;
                            db.SaveChanges();
                            /************************************/

                            Session["UserID"]   = obj.Id;
                            Session["isActive"] = obj.IsActive;
                            Session["UserName"] = obj.Username;
                            return(RedirectToRoute("Main"));
                        }
                        else
                        {
                            ViewBag.Color   = "red";
                            ViewBag.Message = "You're not verified your account";
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.Color   = "red";
                        ViewBag.Message = "Wrong Username or Password";
                        return(View());
                    }
                }
            }
            return(View(regs));
        }
        public ActionResult Register(string submit, string firstname, string lastname, string gender, string username, string password, string confirmpassword, string email, string telepon)
        {
            if (!string.IsNullOrEmpty(submit))
            {
                Registration regs = new Registration();

                Regex   regexEmail = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Boolean matchEmail = regexEmail.IsMatch(email);

                Boolean phoneMatch = true;
                for (int i = 0; i < telepon.Length; i++)
                {
                    phoneMatch = Char.IsNumber(telepon, i);
                    if (phoneMatch == true)
                    {
                        continue;
                    }
                    else
                    {
                        phoneMatch = false;
                        break;
                    }
                }

                if (username == "" || password == "" || email == "" || telepon == "" || firstname == "" || lastname == "")
                {
                    ViewBag.Color   = "red";
                    ViewBag.Message = "No Empty Fields Are Allowed";
                    return(View());
                }
                else if (matchEmail == false)
                {
                    ViewBag.Color   = "red";
                    ViewBag.Message = "Wrong Email Format";
                    return(View());
                }
                else if (phoneMatch == false)
                {
                    ViewBag.Color   = "red";
                    ViewBag.Message = "Wrong Phone Number Format";
                    return(View());
                }
                else if (confirmpassword != password)
                {
                    ViewBag.Color   = "red";
                    ViewBag.Message = "Password Isn't Match";
                    return(View());
                }
                else
                {
                    string encoded = Encryption(password);
                    Guid   guid    = Guid.NewGuid();
                    using (ASPMVCDB db = new ASPMVCDB())
                    {
                        // Check Email and Username Availability
                        int objUser  = db.Registration.Where(model => model.Username.Equals(username)).Count();
                        int objEmail = db.Registration.Where(model => model.Email.Equals(email)).Count();
                        if (objUser > 0 || objEmail > 0)
                        {
                            ViewBag.Color   = "red";
                            ViewBag.Message = "Username or Email Is Already Registered";
                            return(View());
                        }
                        else if (objUser > 0 && objEmail > 0)
                        {
                            ViewBag.Color   = "red";
                            ViewBag.Message = "Username or Email Is Already Registered";
                            return(View());
                        }
                        else
                        {
                            string uniqid     = guid.ToString();
                            string VerifyCode = ScrambleWord(uniqid.Replace("-", ""));
                            string code       = VerifyCode.Substring(0, 10);

                            regs.Id                   = uniqid;
                            regs.Firstname            = firstname;
                            regs.Lastname             = lastname;
                            regs.Username             = username;
                            regs.Gender               = gender;
                            regs.Password             = encoded;
                            regs.ConfirmPassword      = encoded;
                            regs.Email                = email;
                            regs.Telepon              = telepon;
                            regs.ThemeLink            = "~/Content/theme/default.jpg";
                            regs.Photo                = "~/Content/img/default.jpg";
                            regs.IsActive             = "0";
                            regs.VerifyActivationCode = code;
                            db.Registration.Add(regs);
                            db.SaveChanges();

                            Session["IDUser"] = uniqid;
                            long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                            TempData["code"] = code;
                            TempData.Keep("code");
                            return(RedirectToRoute("Verify", new { id = milliseconds }));
                        }
                    }
                }
            }
            else
            {
                return(new EmptyResult());
            }
        }