Esempio n. 1
0
        private Guid GetUserCompanyId()
        {
            Guid  companyId = Guid.Empty;
            Roles oRoles    = new Roles();

            if (oRoles.IsUserInRole(User.Identity.Name, "Company"))
            {
                var  oUser    = new SmartMarket.Web.Business.User();
                long userId   = oUser.GetUserId(User.Identity.Name);
                var  oCompany = db.Companies.SingleOrDefault(c => c.UserId == userId);
                if (oCompany != default(Company))
                {
                    companyId = oCompany.Id;
                }
            }
            return(companyId);
        }
Esempio n. 2
0
        public IHttpActionResult Login(string userName, string password)
        {
            string IP = HttpContext.Current.Request.UserHostAddress;

            SmartMarket.Web.Business.User _user = new SmartMarket.Web.Business.User();
            if (_user.Authenticate(userName, password, IP))
            {
                Roles oRoles = new Roles();
                if (oRoles.IsUserInRole(userName, "Customer"))
                {
                    return(Json(new { success = true, Message = "", UserId = _user.GetUserId(userName) }));
                }

                return(Json(new { success = false, Message = "no a customer", UserId = -1 }));
            }

            return(Json(new { success = false, Message = "Invalid username or password", UserId = -1 }));
        }