Esempio n. 1
0
        public ActionResult VerifyAccount(string id)
        {
            bool        Status = false;
            DatabaseCon con    = new DatabaseCon();
            var         dc     = con.Access();


            dc.Configuration.ValidateOnSaveEnabled = false;

            var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();

            if (v != null)
            {
                v.IsEmailVerified = true;
                dc.SaveChanges();
                Status = true;
            }
            else
            {
                ViewBag.Message = "Invalid Request";
            }


            ViewBag.Status = Status;

            return(View());
        }
Esempio n. 2
0
        public void AddTask(Models.Task task)
        {
            DatabaseCon con = new DatabaseCon();

            var context = con.Access();

            context.Tasks.Add(task);
            context.SaveChanges();
        }
Esempio n. 3
0
        public bool IsEmailExist(string emailID)
        {
            DatabaseCon con = new DatabaseCon();
            var         dc  = con.Access();


            var v = dc.Users.Where(a => a.EnailID == emailID).FirstOrDefault();

            return(v != null);
        }
Esempio n. 4
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            //

            //Model Validation
            if (ModelState.IsValid)
            {
                //Email is already exist

                var isExist = userService.IsEmailExist(user.EnailID);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();

                #endregion

                #region Password Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);;
                #endregion
                user.IsEmailVerified = false;

                #region Save to Datebase
                DatabaseCon con = new DatabaseCon();
                var         dc  = con.Access();

                dc.Users.Add(user);
                dc.SaveChanges();

                //send email to user
                SendVerificationLink(user.EnailID, user.ActivationCode.ToString());
                message = "Registration successfully done. Account activation link has been sent to your email id :" + user.EnailID;
                Status  = true;

                #endregion
            }
            else
            {
                message = "invalid request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;

            //send email to user

            return(View(user));
        }
Esempio n. 5
0
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            string message = "";

            DatabaseCon con = new DatabaseCon();
            var         dc  = con.Access();


            var v = userService.FindByEmail(login.EnailID);

            if (v != null)
            {
                if (!v.IsEmailVerified)
                {
                    ViewBag.Message = "Please verify your email first";
                    return(View());
                }

                if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
                {
                    int    timeout   = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
                    var    ticket    = new FormsAuthenticationTicket(login.EnailID, login.RememberMe, timeout);
                    string encrypted = FormsAuthentication.Encrypt(ticket);
                    var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                    cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                    cookie.HttpOnly = true;
                    Response.Cookies.Add(cookie);


                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }
            else
            {
                message = "Invalid credential provided";
            }

            ViewBag.Message = message;
            return(View());
        }
Esempio n. 6
0
        public Models.Task findById(int?id)
        {
            Models.Task foundTask = new Models.Task();

            DatabaseCon con = new DatabaseCon();

            var context = con.Access();


            foundTask = context.Tasks.FirstOrDefault(x => x.TaskID == id);



            return(foundTask);
        }
Esempio n. 7
0
        public void Remove(Models.Task deleteTask)
        {
            try
            {
                DatabaseCon con = new DatabaseCon();

                var context = con.Access();
                context.Tasks.Attach(deleteTask);
                context.Tasks.Remove(deleteTask);
                context.SaveChanges();
            }
            catch (System.Exception e)
            {
                //Logger.Info(e.Message);
                // throw new DatabaseException("Cannot connect to database!\n");
            }
        }
Esempio n. 8
0
        public IList <User> FindAll()
        {
            IList <User> users = new List <User>();

            DatabaseCon con = new DatabaseCon();

            var dc = con.Access();


            users = dc.Users.ToList();
            if (users != null)
            {
                return(users);
            }

            else
            {
                return(null);
            }
        }
Esempio n. 9
0
        // GET: Task

        public TaskController()
        {
            userService = new UserService(new UserRepository());
            db          = con.Access();
        }