Exemplo n.º 1
0
        public JsonResult CheckEmailExist(string UserEmailId)
        {
            int?LoginMemberId = HttpContextAccessor.HttpContext.Session.GetInt32("memberid");
            var EmailExist    = Mem_Repository.GetByParameter(i => i.MemberId != LoginMemberId && i.EmailId == UserEmailId && i.IsDelete == false);

            return(Json(EmailExist));
        }
Exemplo n.º 2
0
        public ActionResult MyAccount()
        {
            int         memberid = Convert.ToInt32(User.FindFirstValue(ClaimTypes.Sid));
            Tbl_Members register = new Tbl_Members();

            register = Mem_Repository.GetByParameter(i => i.MemberId == memberid);
            return(View(register));
        }
Exemplo n.º 3
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = Mem_Repository.GetByParameter(i => i.EmailId == model.UserEmailId);

                if (user != null)
                {
                    string DecryptedPassword = protector.Unprotect(user.Password);
                    if (DecryptedPassword == model.Password)
                    {
                        //Check the user name and password
                        //Here can be implemented checking logic from the database
                        ClaimsIdentity identity        = null;
                        bool           isAuthenticated = false;

                        if (user.RoleId == 1)
                        {
                            //Create the identity for the Admin
                            identity = new ClaimsIdentity(new[] {
                                new Claim(ClaimTypes.Name, user.FirstName),
                                new Claim(ClaimTypes.Role, "Admin"),
                                new Claim(ClaimTypes.Sid, Convert.ToString(user.MemberId)),
                            }, CookieAuthenticationDefaults.AuthenticationScheme);
                            this.session.SetInt32("memberid", user.MemberId);
                            isAuthenticated = true;
                        }

                        if (user.RoleId == 2)
                        {
                            //Create the identity for the User
                            identity = new ClaimsIdentity(new[] {
                                new Claim(ClaimTypes.Name, user.FirstName),
                                new Claim(ClaimTypes.Role, "User"),
                                new Claim(ClaimTypes.Sid, Convert.ToString(user.MemberId)),
                            }, CookieAuthenticationDefaults.AuthenticationScheme);
                            this.session.SetInt32("memberid", user.MemberId);
                            isAuthenticated = true;
                        }

                        if (isAuthenticated)
                        {
                            var principal = new ClaimsPrincipal(identity);

                            var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
                            if (!string.IsNullOrEmpty(returnUrl))
                            {
                                return(Redirect(returnUrl));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "Home"));
                            }
                        }
                        else
                        {
                            if (user != null && user.IsActive == false)
                            {
                                ModelState.AddModelError("Password", "Your account in not verified");
                            }
                            else
                            {
                                ModelState.AddModelError("Password", "Invalid username or password");
                            }
                        }
                    }
                }
                else
                {
                    if (user != null && user.IsActive == false)
                    {
                        ModelState.AddModelError("Password", "Your account in not verified");
                    }
                    else
                    {
                        ModelState.AddModelError("Password", "Invalid username or password");
                    }
                }
            }
            return(View(model));
        }