コード例 #1
0
        public ProjectAdminInfo GetProjectAdminInfo(RequestBase req, int userid)
        {
            ProjectAdminInfo adminInfo = new ProjectAdminInfo();

            try
            {
                SqlSvrDAL dal = new SqlSvrDAL(req.ClientInfo);
                adminInfo = dal.GetProjectAdminInfo(userid);
            }
            catch (Exception ex)
            {
                //LogHelper.AddLog("ProjectController,GetProjectAdminInfo", ex.Message, ex.StackTrace, "HCL.Academy.Service", req.ClientInfo.emailId);
                TelemetryClient telemetry = new TelemetryClient();
                telemetry.TrackException(ex);
            }
            return(adminInfo);
        }
コード例 #2
0
        public async Task <ActionResult> Login()
        {
            if (Request.IsAuthenticated)
            {
                var    userClaims = User.Identity as System.Security.Claims.ClaimsIdentity;
                string email      = userClaims?.FindFirst(System.IdentityModel.Claims.ClaimTypes.Name)?.Value;
                await InitializeServiceClient(email);

                string name            = "";
                string serviceuserName = ConfigurationManager.AppSettings["SP_ServiceAccountID"].ToString();
                if (serviceuserName.ToUpper() == email.ToUpper())
                {
                    string[] parts = serviceuserName.Split("@".ToCharArray());
                    name = parts[0];
                }
                else
                {
                    name = userClaims?.FindFirst("name")?.Value;
                }

                HttpResponseMessage rolesresponse = await client.PostAsJsonAsync("User/GetUserActiveStatus?emailAddress=" + email, req);

                string activeStatus = await rolesresponse.Content.ReadAsAsync <string>();

                if (activeStatus.ToUpper() == "TRUE")
                {
                    SPAuthUtility objAuth = new SPAuthUtility();
                    UserManager   user    = await objAuth.AuthorizeServiceAccount(email, name);

                    if (user != null && user.GroupPermission > 0)
                    {
                        Session.Add("IsOnline", user.IsOnline);

                        HttpResponseMessage admininforesponse = await client.PostAsJsonAsync("Project/GetProjectAdminInfo?userid=" + user.DBUserId, req);

                        ProjectAdminInfo admininfo = await admininforesponse.Content.ReadAsAsync <ProjectAdminInfo>();

                        user.Admininfo = admininfo;
                        //  FormsAuthentication.SetAuthCookie(objAuth.DisplayName, objAuth.RememberMe);

                        if (Session["CurrentUser"] == null)
                        {
                            Session.Add("CurrentUser", user);
                        }
                        else
                        {
                            Session.Remove("CurrentUser");
                            Session.Add("CurrentUser", user);
                        }
                        return(RedirectToAction("Home", "Home"));
                    }

                    if (user != null && user.GroupPermission == 0)
                    {
                        ModelState.AddModelError("", "You are not Authorized to Log in");
                    }

                    if (user == null)
                    {
                        ModelState.AddModelError("", "Username and/or Password is incorrect");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Your userid has been deactivated.Please contact administrator");
                }
            }
            FetchAppConfig();
            return(View());
        }
コード例 #3
0
        public async Task <ActionResult> Login(SPAuthUtility objAuth)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    InitializeServiceClient(objAuth.UserName);
                    HttpResponseMessage rolesresponse = await client.PostAsJsonAsync("User/GetUserActiveStatus?emailAddress=" + objAuth.UserName, req);

                    string activeStatus = await rolesresponse.Content.ReadAsAsync <string>();

                    if (activeStatus.ToUpper() == "TRUE")
                    {
                        HttpResponseMessage response = await client.PostAsJsonAsync("ExternalUser/GetExternalUserByUserName?UserName="******"SP_ServiceAccountID"].ToString();
                        //    string name = authResponse.Name;
                        //}

                        #region AspIdentity
                        // This doesn't count login failures towards account lockout
                        // To enable password failures to trigger account lockout, change to shouldLockout: true
                        var result = await SignInManager.PasswordSignInAsync(objAuth.UserName, objAuth.Password, false, true);

                        #endregion
                        if (result.ToString().ToUpper() == "FAILURE")
                        {
                            ModelState.AddModelError("", "Username and/or Password is incorrect.");
                        }
                        else if (result.ToString().ToUpper() == "LOCKEDOUT")
                        {
                            ModelState.AddModelError("", "Your account is lockedout.Try after some time.");
                        }
                        else if (result.ToString().ToUpper() == "SUCCESS")
                        {
                            ExternalUserRequest extuser = new ExternalUserRequest();
                            extuser.ClientInfo = req.ClientInfo;
                            extuser.UserName   = objAuth.UserName;
                            HttpResponseMessage groupresponse = await client.PostAsJsonAsync("ExternalUser/GetUserMemberShip", extuser);

                            List <UserGroupMemberShip> groupMemberships = await groupresponse.Content.ReadAsAsync <List <UserGroupMemberShip> >();

                            int           groupPermission = 0;
                            List <string> groups          = new List <string>();
                            if (groupMemberships.Count > 0)
                            {
                                for (int i = 0; i < groupMemberships.Count; i++)
                                {
                                    groups.Add(groupMemberships[i].GroupName);
                                    if (groupMemberships[i].GroupPermission > groupPermission)
                                    {
                                        groupPermission = groupMemberships[i].GroupPermission;
                                    }
                                }
                            }
                            UserManager user = new UserManager();
                            user.GroupPermission = groupPermission;
                            user.Groups          = groups;
                            user.UserName        = authResponse.Name;
                            user.DBUserId        = Convert.ToInt32(authResponse.UserId);
                            user.EmailID         = authResponse.UserName;
                            user.IsExternalUser  = true;

                            if (user != null && user.GroupPermission > 0)
                            {
                                HttpResponseMessage admininforesponse = await client.PostAsJsonAsync("Project/GetProjectAdminInfo?userid=" + user.DBUserId, req);

                                ProjectAdminInfo admininfo = await admininforesponse.Content.ReadAsAsync <ProjectAdminInfo>();

                                user.Admininfo = admininfo;
                                if (Session["CurrentUser"] == null)
                                {
                                    Session.Add("CurrentUser", user);
                                }
                                else
                                {
                                    Session.Remove("CurrentUser");
                                    Session.Add("CurrentUser", user);
                                }
                                if (authResponse.FirstPasswordChanged)
                                {
                                    return(RedirectToAction("Home", "Home"));
                                }
                                else
                                {
                                    return(RedirectToAction("ResetPassword", "Account"));
                                }
                            }

                            if (user != null && user.GroupPermission == 0)
                            {
                                ModelState.AddModelError("", "You are not Authorized to Log in");
                            }

                            if (user == null)
                            {
                                ModelState.AddModelError("", "Username and/or Password is incorrect");
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Your userid has been deactivated.Please contact administrator");
                    }
                }
            }
            catch (Exception ex)
            {
                // Utilities.LogToEventVwr(ex.Message, 0);
                if (ex.Message.Contains("denied"))
                {
                    ModelState.AddModelError("", "You are not Authorized to Log in");
                }
                else
                {
                    ModelState.AddModelError("", "Username and/or Password is incorrect");
                }
            }
            return(View(objAuth));
        }