示例#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);
        }
示例#2
0
        public Guid InsertLogin(BE.User objUser)
        {
            try
            {
                Guid newid = Guid.Empty;
                cmd             = new SqlCommand("InsertUsers", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@username", objUser.username);
                cmd.Parameters.AddWithValue("@password", objUser.password);
                cmd.Parameters.Add("@uid", SqlDbType.UniqueIdentifier);
                cmd.Parameters["@uid"].Direction = ParameterDirection.Output;

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                newid = new Guid(cmd.Parameters["@uid"].Value.ToString());
                return(newid);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                con.Close();
            }
        }
示例#3
0
 public BE.User login(BE.User objBEUser)
 {
     try
     {
         BusinessEntity.User rtvBEUser = null;
         cmd             = new SqlCommand("VerifyLogin", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@username", objBEUser.username);
         cmd.Parameters.AddWithValue("@password", objBEUser.password);
         con.Open();
         DataTable dt = new DataTable();
         dt.Load(cmd.ExecuteReader());
         con.Close();
         if (dt.Rows.Count > 0)
         {
             rtvBEUser          = new BusinessEntity.User();
             rtvBEUser.uid      = new Guid(dt.Rows[0]["uid"].ToString());
             rtvBEUser.username = dt.Rows[0]["username"].ToString();
         }
         return(rtvBEUser);
     }
     catch (Exception ex)
     {
         throw;
     }
     finally
     {
         con.Close();
     }
 }
示例#4
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);
        }
示例#5
0
 public BE.User Login(BE.User objUser)
 {
     try
     {
         objUserLogic = new UserLogic();
         BE.User rtvUser = null;
         rtvUser = objUserLogic.Login(objUser);
         return(rtvUser);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#6
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);
        }