예제 #1
0
        // Get the current user's email address from their profile.
        public async Task <IGraphServiceOrganizationCollectionPage> GetOrganisationInfo(GraphServiceClient graphClient)
        {
            // Get the current user.
            // This sample only needs the user's email address, so select the mail and userPrincipalName properties.
            // If the mail property isn't defined, userPrincipalName should map to the email for all account types.
            IGraphServiceOrganizationCollectionPage org = await graphClient.Organization.Request().GetAsync();

            return(org);
        }
예제 #2
0
        //public async Task<ActionResult> GoToRegister(CompanyLicenseViewModel cModel)
        public async Task <ActionResult> GoToRegister()
        {
            GraphServiceClient graphClient1 = SDKHelper.GetAuthenticatedClient();
            IGraphServiceOrganizationCollectionPage organization = await graphService.GetOrganisationInfo(graphClient1);

            if (organization.Count == 0)
            {
                return(View("~/Views/Shared/GoToLogin.cshtml"));
            }

            GraphServiceClient graphClient2 = SDKHelper.GetAuthenticatedClient();

            // Get the current user's email address.
            //Microsoft.Graph.User me = await graphClient.Me.Request().Select("mail, userPrincipalName, displayName, jobTitle").GetAsync();
            Microsoft.Graph.User me = await graphService.GetUserInfo(graphClient2);

            //me.Mail ?? me.UserPrincipalName;
            string email       = me.Mail ?? me.UserPrincipalName;
            string displayName = me.DisplayName;
            string companyName = organization.CurrentPage[0].DisplayName;
            string website     = organization.CurrentPage[0].VerifiedDomains.ElementAt(0).Name; //me.MySite;
            string jobTitle    = me.JobTitle;

            RegistrationViewModel model = new RegistrationViewModel();

            model.EmailID       = email;
            model.CustomerName  = displayName;
            model.DomainName    = website;
            model.Name          = companyName;
            model.BusinessTitle = jobTitle;
            //model.CustomerType = cModel.CompanyLicenseType;
            model.CustomerType = "Premium";

            ViewBag.PageType = "Register";

            //ViewBag.citieslist = _cityRepository.GetAllElements().Select(x => new SelectListItem
            //{
            //    Value = x.CityName,
            //    Text = x.CityName
            //});


            ViewBag.countrieslist = _cityRepository.GetAllElements().Select(x => new { x.CountryName }).OrderBy(x => x.CountryName).ToList().Distinct().Select(x => new SelectListItem
            {
                Value = x.CountryName,
                Text  = x.CountryName
            });

            ViewBag.industrieslist = _industryRepository.GetAllElements().OrderBy(x => x.IndustryName).ToList().Select(x => new SelectListItem
            {
                Value = x.IndustryName,
                Text  = x.IndustryName
            });

            return(View("~/Views/Registration/Register.cshtml", model));
        }
예제 #3
0
        // Create a new user in the signed-in user's tenant.
        // This snippet requires an admin work account.
        public async Task <List <ResultsItem> > CreateUser(GraphServiceClient graphClient)
        {
            List <ResultsItem> items = new List <ResultsItem>();
            string             guid  = Guid.NewGuid().ToString();

            // This snippet gets the tenant domain from the Organization object to construct the user's email address.
            IGraphServiceOrganizationCollectionPage organization = await graphClient.Organization.Request().GetAsync();

            string alias  = Resource.User.ToLower() + guid.Substring(0, 8);
            string domain = organization.CurrentPage[0].VerifiedDomains.ElementAt(0).Name;

            // Add the user.
            User user = await graphClient.Users.Request().AddAsync(new User
            {
                AccountEnabled  = true,
                DisplayName     = Resource.User + guid.Substring(0, 8),
                MailNickname    = alias,
                PasswordProfile = new PasswordProfile
                {
                    Password = Resource.Prop_Password
                },
                UserPrincipalName = alias + "@" + domain
            });

            if (user != null)
            {
                // Get user properties.
                items.Add(new ResultsItem
                {
                    Display    = user.DisplayName,
                    Id         = user.Id,
                    Properties = new Dictionary <string, object>
                    {
                        { Resource.Prop_Upn, user.UserPrincipalName },
                        { Resource.Prop_Id, user.Id }
                    }
                });
            }
            return(items);
        }
예제 #4
0
        public IEnumerable <List <Organization> > GetOrganizations(CancellationToken token)
        {
            IGraphServiceOrganizationCollectionPage page = null;

            try
            {
                page = client.Organization.Request().GetAsync(token).Result;
            }
            catch (Exception ex)
            {
                HandleException(ex, null, messageOnlyExceptions, "GetOrganizations");
            }

            while (page != null)
            {
                yield return(page.ToList());

                if (page.NextPageRequest == null)
                {
                    break;
                }
                page = page.NextPageRequest.GetAsync(token).Result;
            }
        }
예제 #5
0
        public async Task <ActionResult> MSOLoginRedirect()
        {
            string encryptedCompanyID = string.Empty;
            string encodedCompanyID   = string.Empty;

            string rolename = string.Empty;

            //GenerateRandomCryptographicKey cmsKey
            string cmsKey = string.Empty;

            cmsKey = GenerateRandomKey(12);

            try
            {
                GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();

                string useremail = await graphService.GetMyEmailAddress(graphClient);

                MyCard.Domain.User user = null;

                MyCard.Domain.Company company = null;
                company = await _companyRepository.GetFirstOrDefaultAsync(o => o.Email == useremail);

                Expression <Func <MyCard.Domain.User, object> >[] includes =
                {
                    x => x.UserRoles
                };

                if (company != null)
                {
                    user = await _userRepository.GetFirstOrDefaultAsync(o => o.Email == useremail, default(CancellationToken), includes);

                    encryptedCompanyID = MyCard.Helper.EncryptionHelper.EncryptString(Convert.ToString(user.CompanyId));
                    encodedCompanyID   = HttpUtility.UrlEncode(encryptedCompanyID);

                    foreach (var item in user.UserRoles)
                    {
                        if (item.RoleId == 1)
                        {
                            rolename = "super_admin";
                        }
                        else if (item.RoleId == 2)
                        {
                            rolename = "company_owner";
                        }
                        else
                        {
                            rolename = "user";
                        }
                    }

                    if (rolename == "company_owner")
                    {
                        var authTicket = new FormsAuthenticationTicket(
                            1,
                            user.Name + "|" + user.Id + "|" + user.CompanyId + "|" + encodedCompanyID + "|" + cmsKey, //user id
                            DateTime.Now,
                            DateTime.Now.AddDays(3),                                                                  // expiry
                            false,                                                                                    //true to remember
                            rolename,                                                                                 //roles
                            "/"
                            );

                        //encrypt the ticket and add it to a cookie
                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                        Response.Cookies.Add(cookie);

                        //if(company.CustomerType=="Freemium")
                        //{
                        //    return RedirectToAction("Index", "CompanyDashboard");
                        //}

                        //Update Cms_key here
                        company = await _companyRepository.GetFirstOrDefaultAsync(o => o.Id == user.CompanyId);

                        company.CmsAccessKey = cmsKey;


                        _companyRepository.SetModified(company);
                        await _companyRepository.UnitOfWork.CommitAsync();

                        PurchaseOrder poUpload = _purchaseOrderRepository.GetFilteredElements(x => x.CompanyId == user.CompanyId).OrderByDescending(x => x.Id).FirstOrDefault();

                        if (poUpload != null)
                        {
                            if (poUpload.OrderFile == null || poUpload.FileName == null)
                            {
                                return(RedirectToAction("UploadPO", "CompanyDashboard"));
                            }
                            else
                            {
                                return(RedirectToAction("Index", "CompanyDashboard"));
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Purchase", "CompanyDashboard"));
                        }
                    }
                    else
                    {
                        //ViewBag.Message = MyCard.Web.Resources.ErrorMessages.UserNamePasswordNotMatch;
                        return(RedirectToAction("Login", "CompanyDashboard"));
                    }
                }
                else
                {
                    //Get Organisation Data
                    //IGraphServiceOrganizationCollectionPage organization = await graphClient.Organization.Request().GetAsync();

                    GraphServiceClient graphClient1 = SDKHelper.GetAuthenticatedClient();
                    IGraphServiceOrganizationCollectionPage organization = await graphService.GetOrganisationInfo(graphClient1);

                    if (organization.Count == 0)
                    {
                        return(View("~/Views/Shared/GoToLogin.cshtml"));
                    }

                    //Commenting Below as the Freemium is now being disabled.
                    //Adding new requirement of Freemium and Premium
                    //return RedirectToAction("CompanyLicense", "Home");


                    GraphServiceClient graphClient2 = SDKHelper.GetAuthenticatedClient();

                    // Get the current user's email address.
                    //Microsoft.Graph.User me = await graphClient.Me.Request().Select("mail, userPrincipalName, displayName, jobTitle").GetAsync();
                    Microsoft.Graph.User me = await graphService.GetUserInfo(graphClient2);

                    //me.Mail ?? me.UserPrincipalName;
                    string email       = me.Mail ?? me.UserPrincipalName;
                    string displayName = me.DisplayName;
                    string companyName = organization.CurrentPage[0].DisplayName;
                    string website     = organization.CurrentPage[0].VerifiedDomains.ElementAt(0).Name; //me.MySite;
                    string jobTitle    = me.JobTitle;

                    RegistrationViewModel model = new RegistrationViewModel();
                    model.EmailID       = email;
                    model.CustomerName  = displayName;
                    model.DomainName    = website;
                    model.Name          = companyName;
                    model.BusinessTitle = jobTitle;

                    ViewBag.PageType = "Register";

                    return(View("~/Views/Registration/Register.cshtml", model));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "CompanyDashboard"));
            }
        }