Beispiel #1
0
        public ActionResult LoginActionSubmit(Authentication authentication)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Message = "Please enter your email id and password to login to Athena CRM";
                return(View("Index"));
            }

            Authentication returnAuthentication = new AuthenticationDao().LoginSearch(authentication);

            if (returnAuthentication?.UserType != null)
            {
                Session["UserId"]   = returnAuthentication.LoginId;
                Session["UserType"] = returnAuthentication.UserType;
                Session["UserName"] = returnAuthentication.UserName;
                ViewBag.Message     = "Please enter your email id and password to login to Athena CRM";
                return(RedirectToAction("MemberSearch", "Members"));
            }
            else
            {
                ViewBag.Message = "Sorry, unable to athentication with the given credentials";
            }

            return(View("Index"));
        }
Beispiel #2
0
        public static void DeleteAndInvalidateOldSessions()
        {
            //Check to see if the user has an old cookie.
            String oldSessionId = GetSessionCookieValue();

            if (oldSessionId != null)
            {
                var userSession = AuthenticationDao.GetUserSession(oldSessionId);
                if (userSession != null)
                {
                    AuthenticationDao.DeleteUserSession(userSession);
                }
            }

            RemoveSessionCookie();

            if (AuthenticatedSession.Current.UserSessionId.HasValue)
            {
                if (oldSessionId == null || !AuthenticatedSession.Current.UserSessionId.Equals(oldSessionId))
                {
                    var userSession = AuthenticationDao.GetUserSession(AuthenticatedSession.Current.UserSessionId.Value.ToString());
                    if (userSession != null)
                    {
                        AuthenticationDao.DeleteUserSession(userSession);
                    }
                }
            }

            //Invalidate any old Session
            SetServerSessionAsInvalidated();
        }
        public void Execute(ModifyUserDetailsParameters parameters)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            IAuthenticationDao dao = new AuthenticationDao(connectionString);

            dao.ModifyUserDetails(parameters);
        }
        public IList <FindUserLogonDetailsResult> Execute(FindUserLogonDetailsParameters parameters)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            IAuthenticationDao dao = new AuthenticationDao(connectionString);

            return(dao.FindUserLogonDetails(parameters));
        }
Beispiel #5
0
        private static bool _IsValid(string sessionId)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(sessionId) == true)
                {
                    DeleteAndInvalidateOldSessions();
                    return(false);
                }

                UserSession userSession = AuthenticationDao.GetUserSession(sessionId);
                if (userSession == null)
                {
                    DeleteAndInvalidateOldSessions();
                    return(false);
                }

                var loggerData = new LoggerData()
                {
                    { "userId", userSession.UserId },
                    { "userSessionId", sessionId },
                    { "userAgent", userSession.UserAgent },
                    { "browserName", userSession.BrowserName },
                    { "operatingSystem", userSession.OS_Name },
                    { "operatingSystemVersion", userSession.OS_Version },
                    { "lastActivity", userSession.LastActivity },
                };

                Log.Info("Possible bad session check", loggerData);

                if (userSession != null)
                {
                    userSession.UpdateLastActivity();
                    AuthenticationDao.SaveOrUpdateUserSession(userSession);
                }

                SetServerSessionAsValidated(userSession.UserSessionId, Guid.Parse(userSession.UserId));

                if (userSession.KeepAlive)
                {
                    SetSessionCookie(userSession.UserSessionId.ToString(), true);
                }
            }
            catch (Exception e)
            {
                Log.Fatal("An error occurred Validating Session", null, e);
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public static UserSession OnLogin(string userId, bool keepAlive, UserSession existingSession, HttpRequestBase request)
        {
            if (existingSession == null)
            {
                DeleteAndInvalidateOldSessions();
            }

            var session = existingSession ?? new UserSession();

            session.UserId    = userId;
            session.KeepAlive = keepAlive;

            if (request != null)
            {
                var userAgent = request.UserAgent;
                var browser   = request.Browser.Browser;
                var ipAddress = request.UserHostAddress;

                var os = request.Browser.Platform;
                if (String.IsNullOrEmpty(os) || os.ToLower() == "unknown")
                {
                    os = _GetOSfromUserAgent(userAgent);
                }

                session.UserAgent      = userAgent;
                session.BrowserName    = browser;
                session.BrowserVersion = request.Browser.MajorVersion.ToString();
                session.OS_Name        = os;
            }
            else if (existingSession != null)
            {
                session.UserAgent      = existingSession.UserAgent;
                session.BrowserName    = existingSession.BrowserName;
                session.BrowserVersion = existingSession.BrowserVersion;
                session.OS_Name        = existingSession.OS_Name;
            }

            //AccountDao.MarkAccountAsVerified(userId);

            AuthenticationDao.SaveOrUpdateUserSession(session);

            //Set the server's Session properties
            SetServerSessionAsValidated(session.UserSessionId, Guid.Parse(session.UserId));

            //Set the Cookies
            SetSessionCookie(session.UserSessionId.ToString(), keepAlive);

            return(session);
        }
        public LogonResult Execute(LogonParameters parameters)
        {
            LogonResult result = null;

            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            IAuthenticationDao dao = new AuthenticationDao(connectionString);

            result = dao.Logon(parameters);

            if (!string.IsNullOrEmpty(result.AlarmId))
            {
                RaiseAlarmAction.Execute(result.AlarmId);
            }

            return(result);
        }
Beispiel #8
0
        private static Guid?IsLoggedIn(System.Collections.Specialized.NameValueCollection headers, HttpCookieCollection cookies)
        {
            string sessionId = GetXAuthToken(headers);

            if (string.IsNullOrWhiteSpace(sessionId) && cookies[SESSION_ID_COOKIE_NAME] != null)
            {
                sessionId = cookies[SESSION_ID_COOKIE_NAME].Value;
            }

            if (!string.IsNullOrWhiteSpace(sessionId))
            {
                var session = AuthenticationDao.GetUserSession(sessionId);
                if (session != null)
                {
                    return(Guid.Parse(session.UserId));
                }
            }
            return(null);
        }
Beispiel #9
0
        public static Guid AuthenticateUser(string username, string password, bool createSession = true)
        {
            var userId = AuthenticationDao.AuthenticateUser(username, password);

            if (!userId.HasValue)
            {
                throw new AppWebException(AppWebExceptionType.InvalidUsernamePassword, new LoggerData()
                {
                    { "username", username }, { "password", password }
                });
            }

            if (createSession)
            {
                SecurityManager.OnLogin(userId.Value.ToString(), true);
            }

            return(userId.Value);
        }
Beispiel #10
0
        public IList <FindUserCompaniesResult> Execute(FindUserCompaniesParameters parameters)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[schemaName];
            string connectionString           = settings.ConnectionString;

            bool isAdministratorModeEnabled = false;

            bool.TryParse(ConfigurationManager.AppSettings["AdministratorMode"], out isAdministratorModeEnabled);

            IAuthenticationDao dao = new AuthenticationDao(connectionString);

            if (isAdministratorModeEnabled)
            {
                return(dao.FindAllCompanies());
            }
            else
            {
                return(dao.FindUserCompanies(parameters));
            }
        }
Beispiel #11
0
        public static string CheckLoginNoSession(HttpContext context)
        {
            string sessId = GetXAuthToken(context.Request.Headers);

            if (sessId == null && context.Request.Cookies[SESSION_ID_COOKIE_NAME] != null)
            {
                sessId = context.Request.Cookies[SESSION_ID_COOKIE_NAME].Value;
            }

            if (string.IsNullOrEmpty(sessId))
            {
                throw new AppWebException("No Session ID Found", HttpStatusCode.Unauthorized);
            }

            var session = AuthenticationDao.GetUserSession(sessId);

            if (session != null)
            {
                return(session.UserId);
            }

            throw new AppWebException("No Session Found", HttpStatusCode.Unauthorized);
        }
Beispiel #12
0
        public ActionResult <LoginResult> CaretakerLogin([FromBody] Credential credential)
        {
            var dao = new AuthenticationDao();

            return(dao.CaretakerLogin(credential.Rollno, credential.Password));
        }
        public ActionResult <string> Login([FromBody] Credential credential)
        {
            var dao = new AuthenticationDao();

            return(dao.login(credential.username, credential.password).ToString().ToLower());
        }