Exemple #1
0
        public IActionResult SignIn()
        {
            var userInfo = _userInfoService.GetCurrentUserInfo();

            // Добавил Максим. Блокировка загрузки страницы регистрации, если пользватель залогирован
            if ((userInfo != null) && (!string.IsNullOrEmpty(userInfo.OrganizationId())))
            {
                return(RedirectToAction("Index", "Home"));
            } // конец

            var employee = new SignInEditModel()
            {
                Position   = userInfo?.Position(),
                LastName   = userInfo?.LastName(),
                MiddleName = userInfo?.MiddleName(),
                UserPhone  = userInfo?.Phone(),
                Address    = userInfo?.Address(),
                UserEmail  = userInfo?.Email(),
                EDRPOU     = userInfo?.EDRPOU(),
                SertCode   = userInfo?.SerialNumber(),
                UserName   = userInfo?.Name(),
                INN        = userInfo?.INN()
            };

            employee.Name = string.IsNullOrEmpty(userInfo?.EDRPOU()) ? userInfo?.FullName() : userInfo?.Name();

            return(View(employee));
        }
Exemple #2
0
        public (Guid organizationId, Guid employeeId, Guid profileId, Guid personId) SaveSignIn(SignInEditModel model,
                                                                                                string path)
        {
            var organization = new OrganizationExt();

            if (!string.IsNullOrEmpty(model.EDRPOU))
            {
                organization = _context.Organizations.FirstOrDefault(x => x.EDRPOU == model.EDRPOU);
            }
            else
            {
                organization = null;
            }

            if (organization == null)
            {
                organization = new OrganizationExt
                {
                    Name   = model.Name,
                    EDRPOU = model.EDRPOU,
                    EMail  = model.OrgEmail,
                    INN    = !string.IsNullOrEmpty(model.EDRPOU) ? null : model.INN
                };

                _context.Add_Auditable(organization);
                _context.SaveChanges();

                var licenses = _limsService.GetLicenses("",
                                                        !string.IsNullOrEmpty(model.EDRPOU) ? model.EDRPOU : model.INN).Result;

                var trlLicenseIds = new List <string> {
                    "2", "3", "4"
                };

                var orgInfoPRL = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "PRL",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Contains("1"))
                };
                var orgInfoIML = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "IML",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.FirstOrDefault(x => x.LicenseTypesIds.Contains("5")) != null
                };
                var orgInfoTRL = new OrganizationInfo()
                {
                    Name                   = model.Name,
                    Type                   = "TRL",
                    OrganizationId         = organization.Id,
                    IsActualInfo           = true,
                    IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Split("|").Any(y => trlLicenseIds.Contains(y)))
                };
                _context.AddRange_Auditable(orgInfoPRL, orgInfoIML, orgInfoTRL);
                _context.SaveChanges();

                //TODO email
            }

            var person = _context.Person.FirstOrDefault(x => x.IPN == model.INN && x.LastName == model.LastName);

            if (person == null)
            {
                person = new Person
                {
                    LastName   = model.LastName,
                    MiddleName = model.MiddleName,
                    Name       = model.UserName,
                    Phone      = model.UserPhone,
                    IPN        = model.INN,
                    Email      = model.UserEmail,
                    Birthday   = DateTime.MinValue,
                    Caption    = $"{model.LastName} {model.UserName} {model.MiddleName}"
                };
                _context.Add_Auditable(person);
                _context.SaveChanges();
            }

            var employees = _context.EmployeesExt.Where(x => x.PersonId == person.Id)
                            .Include(x => x.DefaultValues)
                            .Include(x => x.Profiles)
                            .ToList();
            var employeeOrg = employees.FirstOrDefault(x => x.OrganizationId == organization.Id);
            var profile     = _context.Profiles.FirstOrDefault(x => x.Caption == "Employee");

            if (employeeOrg != null)
            {
                employeeOrg.Position  = model.Position;
                employeeOrg.UserEmail = model.UserEmail;
                employeeOrg.ReceiveOnChangeAllMessage     = model.ReceiveOnChangeAllMessage;
                employeeOrg.ReceiveOnChangeOwnMessage     = model.ReceiveOnChangeOwnMessage;
                employeeOrg.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication;
                employeeOrg.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication;
                employeeOrg.PersonalCabinetStatus         = model.PersonalCabinetStatus;
                employeeOrg.ReceiveOnChangeOrgInfo        = model.ReceiveOnChangeOrgInfo;
                employeeOrg.ReceiveOnOverduePayment       = model.ReceiveOnOverduePayment;

                try
                {
                    if (employeeOrg.DefaultValues.FirstOrDefault()?.ValueId != organization.Id)
                    {
                        employeeOrg.DefaultValues = new List <UserDefaultValue>
                        {
                            new UserDefaultValue
                            {
                                Caption    = person.Caption,
                                EntityName = nameof(OrganizationExt),
                                ValueId    = organization.Id
                            }
                        };
                    }
                }
                catch (Exception)
                {
                    if (employeeOrg.DefaultValues.Any())
                    {
                        employeeOrg.DefaultValues = new List <UserDefaultValue>
                        {
                            new UserDefaultValue
                            {
                                Caption    = person.Caption,
                                EntityName = nameof(OrganizationExt),
                                ValueId    = organization.Id
                            }
                        };
                    }
                }

                if (employeeOrg.Profiles.Any())
                {
                    employeeOrg.Profiles = new List <UserProfile>
                    {
                        new UserProfile
                        {
                            ProfileId = profile.Id,
                            Caption   = $"{profile.Caption}: {person.Caption}"
                        }
                    };
                }

                _context.SaveChanges();
                if (employeeOrg.UserEmail != model.UserEmail)
                {
                    //TODO Email
                }
            }
            else
            {
                employeeOrg = new EmployeeExt
                {
                    PersonId  = person.Id,
                    Position  = model.Position,
                    UserEmail = model.UserEmail,
                    ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication,
                    ReceiveOnChangeAllMessage     = model.ReceiveOnChangeAllMessage,
                    ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication,
                    ReceiveOnChangeOwnMessage     = model.ReceiveOnChangeOwnMessage,
                    PersonalCabinetStatus         = model.PersonalCabinetStatus,
                    ReceiveOnChangeOrgInfo        = model.ReceiveOnChangeOrgInfo,
                    ReceiveOnOverduePayment       = model.ReceiveOnOverduePayment,
                    OrganizationId = organization.Id,
                    DefaultValues  = new List <UserDefaultValue>
                    {
                        new UserDefaultValue
                        {
                            Caption    = person.Caption,
                            EntityName = nameof(OrganizationExt),
                            ValueId    = organization.Id
                        }
                    },
                    Profiles = new List <UserProfile>
                    {
                        new UserProfile
                        {
                            ProfileId = profile.Id,
                            Caption   = $"{profile.Caption}: {person.Caption}"
                        }
                    }
                };
                _context.Add_Auditable(employeeOrg);
                _context.SaveChanges();
                //TODO Email
            }

            return(organization.Id, employeeOrg.Id, profile.Id, person.Id);
        }
Exemple #3
0
        public IActionResult SignIn(SignInEditModel model)
        {
            if ((string.IsNullOrEmpty(model.EDRPOU)) && (string.IsNullOrEmpty(model.OrgEmail)))
            {
                model.OrgEmail = model.UserEmail;
            }
            else
            if (string.IsNullOrEmpty(model.OrgEmail))
            {
                ModelState.AddModelError("OrgEmail", "Поле необхідне для заповнення");
            }


            if (ModelState.IsValid)
            {
                try
                {
                    var savedData = _tokenService.SaveSignIn(model, $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}");
                    var claims    = new List <Claim>()
                    {
                        new Claim("fullName", $"{model.LastName} {model.UserName} {model.MiddleName}", ClaimValueTypes.String),
                        new Claim("lastname", model.LastName, ClaimValueTypes.String),
                        new Claim("drfocode", model.INN, ClaimValueTypes.String),
                        new Claim("register", "1", ClaimValueTypes.String)
                    };
                    HttpContext.SignOutAsync();

                    _userInfoService.UpdateUserInfo(new UserInfo()
                    {
                        Id = model.INN + model.LastName,
                        UserCultureInfo = new UserCultureInfo(),
                        LoginData       = new Dictionary <string, string>()
                        {
                            { "FullName", $"{model.LastName} {model.UserName} {model.MiddleName}" },
                            { "OrganizationName", model.Name },
                            { "Position", model.Position },
                            { "Name", model.UserName },
                            { "MiddleName", model.MiddleName },
                            { "LastName", model.LastName },
                            { "Email", model.UserEmail },
                            { "Address", model.Address },
                            { "Phone", model.UserPhone },
                            { "EDRPOU", model.EDRPOU },
                            { "INN", model.INN },
                            { "SerialNumber", model.SertCode },
                            { "OrganizationId", savedData.organizationId.ToString() }
                        },
                        UserId    = savedData.employeeId,
                        ProfileId = savedData.profileId,
                        PersonId  = savedData.personId
                    });

                    var userIdentity  = new ClaimsIdentity(claims, "SecureLogin");
                    var userPrincipal = new ClaimsPrincipal(userIdentity);

                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                            userPrincipal,
                                            new AuthenticationProperties
                    {
                        ExpiresUtc   = DateTime.UtcNow.AddHours(8),
                        IsPersistent = false,
                        AllowRefresh = false
                    });
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    HttpContext.SignOutAsync();
                    return(RedirectToAction("Denied", "Auth", new
                    {
                        text = "Нажаль Ви не були зареєстровані на веб-порталі СГД Держлікслужби через помилку зв'язку з сервером. Будь-ласка спробуйте ще раз."
                    }));
                }
                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }