Exemplo n.º 1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "GET, PUT, DELETE, POST, OPTIONS" });
            context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type, Accept, Authorization" });
            context.Response.Headers.Add("Access-Control-Max-Age", new[] { "1728000" });

            BE.User objUser = new BE.User();
            objUser.username = context.UserName;
            objUser.password = context.Password;
            objUserDAL       = new DA.UserDal();
            RetriveUser      = objUserDAL.login(objUser);
            if (string.IsNullOrEmpty(RetriveUser.uid.ToString()))
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            //USERMST usrmst = userService.GetUserInfo(context.UserName, context.Password);
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim("Username", context.UserName));
            //identity.AddClaim(new Claim("FullName", usrmst.User_Name));
            //identity.AddClaim(new Claim("ID", Convert.ToString(usrmst.User_ID)));
            //identity.AddClaim(new Claim("Age", usrmst.User_Age));
            //identity.AddClaim(new Claim("DOB", usrmst.User_DOB));
            //identity.AddClaim(new Claim("Location", usrmst.User_Location));
            //identity.AddClaim(new Claim("Username", context.UserName));
            identity.AddClaim(new Claim(ClaimTypes.Role, "user"));

            context.Validated(identity);
        }
Exemplo n.º 2
0
        public IHttpActionResult Login(BE.User objUser)
        {
            objUserDAL  = new DA.UserDal();
            RetriveUser = objUserDAL.login(objUser);
            if (!string.IsNullOrEmpty(RetriveUser.uid.ToString()))
            {
                return(Ok(new { result = RetriveUser }));
            }

            throw new HttpResponseException(HttpStatusCode.NotFound);
        }
Exemplo n.º 3
0
        public IHttpActionResult Register(BE.User objUser)
        {
            objUserDAL     = new DA.UserDal();
            registeruserid = objUserDAL.InsertLogin(objUser);
            if (registeruserid != Guid.Empty)
            {
                objUserInfoDAL       = new DA.UserInfoDAL();
                objUser.userinfo.uid = registeruserid;
                objUserInfoDAL.InsertUserInfo(objUser.userinfo);

                return(Ok(new { result = objUser }));
            }
            else
            {
                return(BadRequest("Error occure while register"));
            }

            throw new HttpResponseException(HttpStatusCode.NotFound);
        }