Beispiel #1
0
        public IActionResult LoginWithUsernameAndPassword(string phone, string password)
        {
            var found = nguoiDungLogic.CheckUserNameAndPass(phone, password);

            if (found == null)
            {
                return(Ok(new UserLoginDataModel
                {
                    LoginStatus = LoginStatus.InvalidUsernameOrPassword
                }));
            }

            var claims = new Claim[]
            {
                new Claim(ClaimTypes.MobilePhone, phone),
                new Claim(ClaimTypes.NameIdentifier, found.UserID.ToString())
            };
            var token = tokenManager.GenerateToken(claims);

            return(Ok(new UserLoginDataModel(phone, found.UserID.ToString())
            {
                LoginStatus = LoginStatus.Successfull,
                Token = token
            }));
        }
Beispiel #2
0
        public JsonResult AddToCartFun(AddToCartModel objmodel, HttpContextBase httpContext)
        {
            List <AddToCartModel> ListAddtoCart        = new List <AddToCartModel>();
            List <AddToCartModel> CookiesListAddtoCart = null;

            if (Services.GetCookie(httpContext, "addtocart") != null)
            {
                CookiesListAddtoCart = Services.GetMyCart(httpContext, _JwtTokenManager);
                //  ListAddtoCart.Add(objmodel);
                List <AddToCartModel> ListuniqueValues = uniqueValues(CookiesListAddtoCart, objmodel, false);
                // CookiesListAddtoCart.AddRange(ListAddtoCart);

                // var jsonList = JsonConvert.SerializeObject(CookiesListAddtoCart);
                var jsonList = JsonConvert.SerializeObject(ListuniqueValues);
                Services.SetCookie(httpContext, "addtocart", _JwtTokenManager.GenerateToken(jsonList));

                return(Json(jsonList));
            }
            else
            {
                ListAddtoCart.Add(objmodel);
                var jsonList = JsonConvert.SerializeObject(ListAddtoCart);
                Services.SetCookie(httpContext, "addtocart", _JwtTokenManager.GenerateToken(jsonList));
                return(Json(jsonList));
            }
        }
 protected override string Serialize()
 {
     return(JsonConvert.SerializeObject(new
     {
         access_token = JwtTokenManager.GenerateToken(ClientId),
         token_type = "jwt",
         expire_in = this.Lifetime
     }));
 }
        public List <BusinessModel> GetBusiness(long Id)
        {
            var           GetBusiness    = new List <BusinessModel>();
            BusinessModel objUserProfile = new BusinessModel();

            objUserProfile.Id = Id;
            LoginModel MdUser = Services.GetLoginUser(this.ControllerContext.HttpContext, _JwtTokenManager);

            if (MdUser.Id != 0)
            {
                objUserProfile.UserId = Convert.ToInt64(MdUser.Id);
            }

            var           _request    = _JwtTokenManager.GenerateToken(JsonConvert.SerializeObject(objUserProfile));
            ResponseModel ObjResponse = CommonFile.GetApiResponseJWT(Constant.ApiGetBusinessDetail, _request);

            GetBusiness = JsonConvert.DeserializeObject <List <BusinessModel> >(ObjResponse.Response);

            return(GetBusiness);
        }
Beispiel #5
0
        public JsonResult Otp(string Otp, long userid)
        {
            int result           = 1;
            var ReturnjsonString = string.Empty;

            LoginModel ObjLoginModel = new LoginModel();

            ObjLoginModel.Otp = Otp;
            ObjLoginModel.Id  = userid;
            var           _request     = JsonConvert.SerializeObject(ObjLoginModel);
            ResponseModel ObjResponse  = CommonFile.GetApiResponse(Constant.ApiVerifyEmailWithOTP, _request);
            ResponseModel ObjResponse1 = JsonConvert.DeserializeObject <ResponseModel>(ObjResponse.Response);

            if (ObjResponse1.Response == "WRONG OTP")
            {
                result           = 0;
                ReturnjsonString = "{\"Id\":\"" + result + "\"}";
            }
            else
            {
                LoginModel MdUser = Services.GetLoginWebUser(this.ControllerContext.HttpContext, _JwtTokenManager);
                MdUser.RegisterType = "web";

                var jsonString = "{\"Id\":\"" + MdUser.Id + "\",\"Name\":\"" + MdUser.Name + "\",\"ProfileImg\":\"" + MdUser.ProfileImg + "\",\"EmailId\":\"" + MdUser.EmailId + "\",\"Mobile\":\"" + MdUser.Mobile + "\",\"RegisterType\":\"" + MdUser.RegisterType + "\"}";
                Services.SetCookie(this.ControllerContext.HttpContext, "webusr", _JwtTokenManager.GenerateToken(jsonString.ToString()));
                result           = 1;
                ReturnjsonString = "{\"Id\":\"" + result + "\"}";
            }

            //return Json(result, JsonRequestBehavior.AllowGet);
            ReturnjsonString = "{\"Id\":\"" + result + "\"}";
            return(Json(ReturnjsonString));
        }
        public async Task <IActionResult> LoginWithUsernameAndPassword(string username, string password)
        {
            var found = await context.UserAccounts.AnyAsync(e => e.Email == username && e.Password == password);

            if (!found)
            {
                return(Ok(new UserLoginDomain
                {
                    LoginStatus = LoginStatus.InvalidUsernameOrPassword
                }));
            }

            var claims = new Claim[]
            {
                new Claim(ClaimTypes.Email, username)
            };
            var token = tokenManager.GenerateToken(claims);

            return(Ok(new UserLoginDomain(username)
            {
                LoginStatus = LoginStatus.Successfull,
                Token = token
            }));
        }
Beispiel #7
0
        private AuthReponse GetLoginResponse(AuthLoginRequest authLogin)
        {
            var objResp = new AuthReponse();

            try
            {
                if (authLogin != null)
                {
                    if (authLogin.Email == "*****@*****.**")
                    {
                        if (authLogin.Password == "p123")
                        {
                            objResp = _jwtManager.GenerateToken(authLogin.Email, "Admin");
                        }
                        else
                        {
                            objResp.Error = new ErrorResponse {
                                Errors = new List <string> {
                                    "Invalid password"
                                }
                            }
                        };
                    }
                    else
                    {
                        objResp.Error = new ErrorResponse {
                            Errors = new List <string> {
                                "Invalid user"
                            }
                        }
                    };
                }
                else
                {
                    objResp.Error = new ErrorResponse {
                        Errors = new List <string> {
                            "Invalid inputs"
                        }
                    }
                };
            }
            catch (Exception ex)
            {
            }

            return(objResp);
        }
        public IActionResult GetUser([FromBody] User u)
        {
            IActionResult msg = null;

            try
            {
                User user = this._userRepository.GetUser(u.username, u.password);
                user.Token = JwtTokenManager.GenerateToken(user.username, user.Uniquekey, _configuration);
                msg        = Ok(user);
            }
            catch (Exception ex)
            {
                //msg = HttpContext.Response.StatusCode.
                msg = BadRequest(ex.ToString());
            }
            return(msg);
        }
Beispiel #9
0
        public static List <DropDownModel> GetCountry()
        {
            var           CountryList = new List <DropDownModel>();
            DropDownModel objDropdown = new DropDownModel();



            var           _request    = _JwtTokenManager.GenerateToken(JsonConvert.SerializeObject(objDropdown));
            ResponseModel ObjResponse = CommonFile.GetApiResponseJWT(Constant.ApiGetCountry, _request);

            CountryList = JsonConvert.DeserializeObject <List <DropDownModel> >(ObjResponse.Response);


            //var _request = JsonConvert.SerializeObject(objUserProfile);
            //ResponseModel ObjResponse = CommonFile.GetApiResponse(Constant.ApiGetCountry, _request);
            //CountryList = JsonConvert.DeserializeObject<List<DropDownModel>>(ObjResponse.Response);
            return(CountryList);
        }
        public ActionResult ForgetPassword(LoginModel objModel)
        {
            if (String.IsNullOrWhiteSpace(objModel.EmailId))
            {
                ModelState.AddModelError("EmailId", "Email Is Required");
                return(View("Index", objModel));
            }
            String Response     = string.Empty;
            bool   IsValidEmail = CommonFile.ValidateEmailIsValid(objModel.EmailId);

            if (!IsValidEmail)
            {
                ModelState.AddModelError("EmailId", "Email Incorrect");

                //Response = "[{\"Response\":\"" + "Email Incorrect" + "\"}]";
                return(View("Index", objModel));
            }
            //LoginModel ObjLoginModel = new LoginModel();
            //ObjLoginModel.EmailId = emailId;
            var           _request     = _JwtTokenManager.GenerateToken(JsonConvert.SerializeObject(objModel));
            ResponseModel ObjResponse  = CommonFile.GetApiResponseJWT(Constant.ApiIsEmailExist, _request);
            ResponseModel ObjResponse1 = JsonConvert.DeserializeObject <ResponseModel>(ObjResponse.Response);

            string respo = ObjResponse1.Response;

            ViewBag.ResponseMassege = respo;
            if (respo.Equals("Not Exist Email"))
            {
                ViewBag.ResponseMessage = "We couldn't find your account with that information";
                // Response = "[{\"Response\":\"" + respo + "\"}]";
                return(View("Index", objModel));
            }
            #region GetLinkId
            objModel.Operation = "insert";
            var           _requestLink     = _JwtTokenManager.GenerateToken(JsonConvert.SerializeObject(objModel));
            ResponseModel ObjResponseLink  = CommonFile.GetApiResponseJWT(Constant.ApiSaveUserForgetPasswordLink, _requestLink);
            ResponseModel ObjResponseLink1 = JsonConvert.DeserializeObject <ResponseModel>(ObjResponseLink.Response);

            string respoLinkId = ObjResponseLink1.Response;
            #endregion
            String subject        = "ForgetPassword";
            String Forgetpassword = "";

            String userName   = objModel.EmailId;
            String Password   = Forgetpassword;
            String domainName = Constant.DomainUrl;
            String Path       = "Login/WebResetPassword/";

            var jsonString = "{\"EmailId\":\"" + objModel.EmailId + "\",\"Date\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " \",\"Id\":\"" + respoLinkId.ToString() + "\"}";
            //  String jwtToken=  _JwtTokenManager.GenerateToken(jsonString.ToString());
            byte[] byt = System.Text.Encoding.UTF8.GetBytes(jsonString);


            // convert the byte array to a Base64 string
            String Base64     = Convert.ToBase64String(byt);
            String ForgetLink = domainName + Path + Base64;
            string body       = "Click Here <br/> Reset Password <br/>" + "<a href=" + ForgetLink + ">" + ForgetLink + "</a>";
            int    respoEmail = CommonFile.SendMailContact(objModel.EmailId, subject, userName, Password, body);
            // Response = "[{\"Response\":\"" + respoEmail + "\"}]";
            if (respoEmail == 1)
            {
                ViewBag.ResponseMessage = "Please check your email and click the secure link.";
            }
            return(View("Index", objModel));
            //return Json(Response);
        }
Beispiel #11
0
        public ActionResult LoginUser(LoginModel ObjModel)
        {
            if (string.IsNullOrWhiteSpace(ObjModel.EmailId))
            {
                ModelState.AddModelError("EmailId", "Email Or Mobile Required");
                return(View("Index", ObjModel));
            }
            if (string.IsNullOrWhiteSpace(ObjModel.Password))
            {
                ModelState.AddModelError("Password", "Password Required");
                return(View("Index", ObjModel));
            }

            string res;
            long   a;
            string myStr = ObjModel.EmailId;

            res = Int64.TryParse(myStr, out a).ToString();
            if (res == "True")
            {
                ObjModel.Mobile = ObjModel.EmailId;
                if (ObjModel.Mobile.Length != 10)
                {
                    ModelState.AddModelError("EmailId", "Mobile Number Incorrect");
                    return(View("Index", ObjModel));
                }
                ObjModel.EmailId = null;
            }
            else
            {
                bool IsValidEmail = CommonFile.ValidateEmailIsValid(ObjModel.EmailId);
                if (!IsValidEmail)
                {
                    ModelState.AddModelError("EmailId", "Email Incorrect");
                    return(View("Index", ObjModel));
                }

                ObjModel.Mobile = null;
            }

            //Password Encode
            string PasswordEncripy = CommonFile.EncodePasswordMd5(ObjModel.Password);

            ObjModel.Password = PasswordEncripy;
            /////////
            var           _request     = _JwtTokenManager.GenerateToken(JsonConvert.SerializeObject(ObjModel));
            ResponseModel ObjResponse  = CommonFile.GetApiResponseJWT(Constant.ApiLoginUser, _request);
            ResponseModel ObjResponse1 = JsonConvert.DeserializeObject <ResponseModel>(ObjResponse.Response);
            String        VarResponse  = ObjResponse1.Response;

            if (VarResponse.Equals("Email/Password is Incorrect"))
            {
                ViewBag.Response = "Email/Password is Incorrect";
                return(View("Index", ObjModel));
            }
            else if (VarResponse.Equals("Phone/Password is Incorrect"))
            {
                ViewBag.Response = "Phone/Password is Incorrect";
                return(View("Index", ObjModel));
            }
            else
            {
                string[] ArrResponse = VarResponse.Split(',');
                if (ArrResponse[5] == "web")
                {
                    ViewBag.Response = "You don't have privillages to access Admin Panel";
                    return(View("Index", ObjModel));
                }


                var jsonString = "{\"Id\":\"" + ArrResponse[0] + "\",\"Name\":\"" + ArrResponse[1] + "\",\"ProfileImg\":\"" + ArrResponse[2] + "\",\"EmailId\":\"" + ArrResponse[3] + "\",\"Mobile\":\"" + ArrResponse[4] + "\"}";
                Services.SetCookie(this.ControllerContext.HttpContext, "usr", _JwtTokenManager.GenerateToken(jsonString.ToString()));


                //Services.SetCookie(this.ControllerContext.HttpContext, "usrId", ArrResponse[0]);
                //Services.SetCookie(this.ControllerContext.HttpContext, "usrName", ArrResponse[1]);
                //Services.SetCookie(this.ControllerContext.HttpContext, "usrImg", ArrResponse[2]);
                //ViewBag.LoginMessage = "Login Success";
                return(RedirectToAction("Index", "Home"));
            }
            //  String Response = "[{\"Response\":\"" + ObjResponse1.Response + "\"}]";
            // return Json(Response);


            /************************************************************/
            #region Using Json

            /*var _request = JsonConvert.SerializeObject(ObjModel);
             * ResponseModel ObjResponse = GetApiResponse(Constant.ApiLoginUser, _request);
             *
             * if (String.IsNullOrWhiteSpace(ObjResponse.Response))
             * {
             *  return View("Index", ObjModel);
             *
             * }
             *
             * var objResponse = ObjResponse.Response;
             * ResponseModel ObjResponse1 = JsonConvert.DeserializeObject<ResponseModel>(ObjResponse.Response);
             * String VarResponse = ObjResponse1.Response;
             * if (VarResponse.Equals("Email/Password is Incorrect"))
             * {
             *  ViewBag.Response = "Email/Password is Incorrect";
             *  return View("Index", ObjModel);
             * }
             * else
             * {
             *  string[] ArrResponse = VarResponse.Split(',');
             *  Services.SetCookie(this.ControllerContext.HttpContext, "usrId", ArrResponse[0]);
             *  Services.SetCookie(this.ControllerContext.HttpContext, "usrName", ArrResponse[1]);
             *  Services.SetCookie(this.ControllerContext.HttpContext, "usrImg", ArrResponse[2]);
             *  //ViewBag.LoginMessage = "Login Success";
             *  return RedirectToAction("Index", "Home");
             * }
             */
            #endregion
            /////////////////////////
        }
        public void Create(AuthenticationTokenCreateContext context)
        {
            var token = JwtTokenManager.GenerateToken("qinyuanpei");

            context.SetToken(token);
        }