public string ResetExternalUserPassword(ExternalUserRequest req) { string result = string.Empty; try { SqlSvrDAL dal = new SqlSvrDAL(req.ClientInfo); // string salt = GetCSPRNGSalt(); // string encryptedPassword = CreateHash(NewPassword, Encoding.ASCII.GetBytes(salt)); result = dal.ResetExternalUserPassword(req); } catch (Exception ex) { //LogHelper.AddLog("ExternalUserController,ResetExternalUserPassword", ex.Message, ex.StackTrace, "HCL.Academy.Service", req.ClientInfo.emailId); TelemetryClient telemetry = new TelemetryClient(); telemetry.TrackException(ex); } return(result); }
public bool AddProjectSkillResources(ProjectResourcesRequest request) { bool status = false; try { ProjectResources prjRes = new ProjectResources(); prjRes.projectId = request.projectId; prjRes.projectName = request.projectName; prjRes.skillResources = request.skillResources; SqlSvrDAL dal = new SqlSvrDAL(request.ClientInfo); status = dal.AddProjectSkillResources(prjRes); } catch (Exception ex) { // LogHelper.AddLog("ProjectController,AddProjectSkillResources", ex.Message, ex.StackTrace, "HCL.Academy.Service", request.ClientInfo.emailId); TelemetryClient telemetry = new TelemetryClient(); telemetry.TrackException(ex); } return(status); }
public ExternalUserAuthResponse AuthenticateExternalUser(RequestBase req, string UserName, string Password) { ExternalUserAuthResponse response = new ExternalUserAuthResponse(); ExternalUser user = null; bool comp = false; try { SqlSvrDAL dal = new SqlSvrDAL(req.ClientInfo); user = dal.GetExternalUserByUserName(UserName); string encryptedPassword = ""; if (!string.IsNullOrEmpty(user.EncryptedPassword)) { // encryptedPassword = CreateHash(Password, Encoding.ASCII.GetBytes(user.PasswordSalt)); encryptedPassword = PasswordHelper.EncodePassword(Password, user.PasswordSalt); } comp = (0 == string.Compare(user.EncryptedPassword, encryptedPassword, false)); if (comp == false) { response.result = false; response.errorMessage = "Userid & Password do not match"; } else { response.result = true; response.user = user; } } catch (Exception ex) { response.result = false; response.errorMessage = ex.Message; // LogHelper.AddLog("ExternalUserController,AuthenticateExternalUser", ex.Message, ex.StackTrace, "HCL.Academy.Service", req.ClientInfo.emailId); TelemetryClient telemetry = new TelemetryClient(); telemetry.TrackException(ex); } return(response); }
public Object Get(string emailid) { SqlSvrDAL dal = new SqlSvrDAL(); int id = dal.GetUserId(emailid); if (id > 0) { UserManager u = dal.GetUsersByID(id); //Create a List of Claims, Keep claims name short //Set issued at date DateTime issuedAt = DateTime.UtcNow; //set the time when it expires DateTime expires = DateTime.UtcNow.AddDays(1); var tokenHandler = new JwtSecurityTokenHandler(); //create a identity and add claims to the user which we want to log in ClaimsIdentity claimsIdentity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, u.UserName) }); const string sec = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1"; var now = DateTime.UtcNow; var securityKey = new Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(System.Text.Encoding.Default.GetBytes(sec)); var signingCredentials = new Microsoft.IdentityModel.Tokens.SigningCredentials(securityKey, Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature); //create the jwt var token = (JwtSecurityToken) tokenHandler.CreateJwtSecurityToken(issuer: "academy", audience: "academy", subject: claimsIdentity, notBefore: issuedAt, expires: expires, signingCredentials: signingCredentials); var tokenString = tokenHandler.WriteToken(token); return(tokenString); } else { return(null); } }
public bool AddProjectSkillResource(ProjectSkillResourceRequest request) { bool status = false; try { ProjectSkillResource psr = new ProjectSkillResource(); psr.projectId = request.projectId; psr.skillId = request.skillId; psr.competencyLevelId = request.competencyLevelId; psr.expectedResourceCount = request.expectedResourceCount; psr.availableResourceCount = request.availableResourceCount; SqlSvrDAL dal = new SqlSvrDAL(request.ClientInfo); status = dal.AddProjectSkillResource(request.projectId, psr); } catch (Exception ex) { //LogHelper.AddLog("ProjectController,AddProjectSkillResource", ex.Message, ex.StackTrace, "HCL.Academy.Service", request.ClientInfo.emailId); TelemetryClient telemetry = new TelemetryClient(); telemetry.TrackException(ex); } return(status); }
/// <summary> /// Get SP 2013 Online User Details /// </summary> /// <returns></returns> public UserManager Authorize(string userName, string password) { UserManager user = new UserManager(); try { string url = ConfigurationManager.AppSettings["URL"].ToString(); Uri uri = new Uri(url, UriKind.Absolute); var isOnline = false; string SharepointPlatform = ConfigurationManager.AppSettings["SharepointPlatform"].ToString(); if (SharepointPlatform == "SPOnline") { isOnline = true; } user.IsOnline = isOnline; try { //Get User Groups string spReaderGroup = ConfigurationManager.AppSettings["AcademyReaderGroup"].ToString(); string spMemberGroup = ConfigurationManager.AppSettings["AcademyMemberGroup"].ToString(); string spOwnerGroup = ConfigurationManager.AppSettings["AcademyOwnerGroup"].ToString(); string spPmoGroup = ConfigurationManager.AppSettings["AcademyPMO"].ToString(); //Get Client Context using (ClientContext clientContext = new ClientContext(url)) { if (isOnline) { var credential = GetSpOnlineCredential(uri, userName, password); clientContext.Credentials = credential; } else { NetworkCredential credential = new NetworkCredential(userName, password); clientContext.Credentials = credential; } web = clientContext.Web; clientContext.Load(web, w => w.Url, w => w.SiteGroups, w => w.CurrentUser, w => w.CurrentUser.Groups); clientContext.Load(web.CurrentUser); clientContext.ExecuteQuery(); //Assign values to custom object user.SPUserId = web.CurrentUser.Id; user.EmailID = web.CurrentUser.Email; user.UserName = web.CurrentUser.Title; DisplayName = web.CurrentUser.Title; user.isSiteAdmin = web.CurrentUser.IsSiteAdmin; //Groups List <string> grp = new List <string>(); foreach (Group gp in web.CurrentUser.Groups) { grp.Add(gp.Title); } int groupValidation = 0; //Reader Group if (grp.Contains(spReaderGroup)) { groupValidation = 1; user.Groups = grp; user.GroupPermission = groupValidation; } //Members Group if (grp.Contains(spMemberGroup)) { groupValidation = 2; user.Groups = grp; user.GroupPermission = groupValidation; } //Owners Group if (grp.Contains(spOwnerGroup)) { groupValidation = 3; user.Groups = grp; user.GroupPermission = groupValidation; } //Owners Group if (grp.Contains(spPmoGroup)) { groupValidation = 4; user.Groups = grp; user.GroupPermission = groupValidation; } if (groupValidation == 0) { user.Groups = null; user.GroupPermission = groupValidation; } ClientContext = clientContext; string dataStore = ConfigurationManager.AppSettings["DATASTORE"].ToString(); if (dataStore == "SqlSvr") { SqlSvrDAL dal = new SqlSvrDAL(); user.DBUserId = dal.GetUserId(web.CurrentUser.Email); } } } catch (Exception ex) { return(user); } HttpContext.Current.Session["SPCredential"] = ClientContext.Credentials; return(user); } catch (Exception) { user = null; return(user); } }