//private const string url = public override string Check(User userInfo) { var service = Doctor_USStateEN.GetService(""); if (service.GetCount(new FilterExpression(vDoctor_USState.ColumnNames.DoctorID, userInfo.UserID)) >= 1) { return(null); } else { // if our user was doctor and he doesn't have doctor's information var userInRoleService = UserInRoleEN.GetService(""); var rolesList = userInRoleService.GetRolesIDUserID(userInfo.UserID.ToString()); if (rolesList.Contains((long)EntityEnums.RoleEnum.Doctor)) { return("Register/Doctor_USState"); } } return(null); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin"); if (allowedOrigin == null) { allowedOrigin = "*"; } context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); User user = null; try { if (context.UserName == "loginwithsinglesignontoken#") { var userId = UserEN.GetService("").LoginWithLoginToken(context.Password); if (userId != null) { user = UserEN.GetService().GetByIDT(userId.Value, new GetByIDParameters()); } } else if (context.UserName == "loginwithregistertoken#") { user = UserEN.GetService("").LoginWithRegisterOffsiteInfo(context.Password); } else { UserValidateUserNamePasswordSP p = new UserValidateUserNamePasswordSP(); p.UserName = context.UserName; p.Password = context.Password; p.ThrowIfError = true; user = (User)UserEN.GetService("").ValidateUserNamePassword(p); } } catch (UserException ex) { context.SetError("invalid_grant", ex.Message); return; } catch (Exception ex) { context.SetError("invalid_grant", ex.Message); return; } if (user != null) { var roleIds = UserInRoleEN.GetService("").GetRolesIDUserID(user.UserID.ToString()); string roleIdCommaSeparated = FWUtils.EntityUtils.ConvertObjectToString(roleIds); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, user.UserID.ToString())); identity.AddClaim(new Claim("sub", user.UserID.ToString())); //identity.AddClaim(new Claim("role", "user")); identity.AddClaim(new Claim("roleIds", roleIdCommaSeparated)); identity.AddClaim(new Claim("siteId", FWUtils.SecurityUtils.GetCurrentSiteID().ToString())); var props = new AuthenticationProperties(new Dictionary <string, string> { { "as:client_id", (context.ClientId == null) ? string.Empty : context.ClientId }, { "userName", user.UserID.ToString() } }); var ticket = new AuthenticationTicket(identity, props); var validationResult = context.Validated(ticket); if (validationResult == false) { context.SetError("invalid_grant", "Ticket is not valid. Try again."); } // setting cookies for authentication in ASP.NET MVC // ClaimsIdentity cookiesIdentity = await userManager.CreateIdentityAsync(user, //CookieAuthenticationDefaults.AuthenticationType); //CustomIdentity cidentity = new CustomIdentity(user.UserID.ToString(), user.Email.ToString()); ////ClaimsIdentity cookiesIdentity = new ClaimsIdentity(identity.Claims, CookieAuthenticationDefaults.AuthenticationType); //ClaimsIdentity cookiesIdentity = new ClaimsIdentity(cidentity, identity.Claims, CookieAuthenticationDefaults.AuthenticationType, null, null); //context.Request.Context.Authentication.SignIn(cookiesIdentity); //FormsAuthentication.SetAuthCookie(user.UserID.ToString(), true); } } catch (Exception ex) { var msg = FWUtils.ExpLogUtils.ExceptionTranslator.TryToTranslate(ex).Message; context.SetError("error", msg); } }