public async Task f_UpdateUser(Guid p_ID, string p_Password, string p_UserName, string p_Name, string p_SurName, string p_LastName, string p_Email, string p_Mobile, string p_Comment, DateTime?p_Birthday, string p_Address, bool p_EmailConfirmed, bool p_IsLockedOut = false, bool p_IsTax = false)
        {
            Cl_User user = await m_UserManager.FindByIdAsync(p_ID.ToString());

            user.Email          = p_Email;
            user.UserName       = p_UserName;
            user.p_SurName      = p_SurName;
            user.p_Name         = p_Name;
            user.p_LastName     = p_LastName;
            user.p_Mobile       = p_Mobile;
            user.p_Comment      = p_Comment;
            user.p_Birthday     = p_Birthday;
            user.p_Address      = p_Address;
            user.p_IsLockedOut  = p_IsLockedOut;
            user.EmailConfirmed = p_EmailConfirmed;
            await m_UserManager.UpdateAsync(user);

            if (!string.IsNullOrWhiteSpace(p_Password) && User.Identity.Name == user.p_UserName)
            {
                var result = await m_SignInManager.PasswordSignInAsync(p_UserName, p_Password, isPersistent : false, lockoutOnFailure : false);

                if (!result.Succeeded)
                {
                    throw new Exception("Не удалось изменить пользователя.");
                }
            }
        }
Beispiel #2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new Cl_User {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(Input.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(Url.GetLocalUrl(returnUrl)));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task f_SetRolesForUser(string a_UserName, Guid a_OfficeID, ListInRoles[] a_Roles)
        {
            if (string.IsNullOrWhiteSpace(a_UserName))
            {
                throw new Exception("Имя пользователя пустое!");
            }
            Cl_User user = await m_UserManager.FindByNameAsync(a_UserName);

            if (user != null)
            {
                IList <string> delRoles = await m_UserManager.GetRolesAsync(user);

                List <string> addRoles = new List <string>();
                foreach (ListInRoles role in a_Roles)
                {
                    if (role.p_InRole)
                    {
                        addRoles.Add(role.p_RoleName);
                    }
                }
                if (delRoles.Count > 0)
                {
                    await m_UserManager.RemoveFromRolesAsync(user, delRoles);
                }
                if (addRoles.Count > 0)
                {
                    await m_UserManager.AddToRolesAsync(user, addRoles);
                }
                await m_UserManager.UpdateAsync(user);
            }
            else
            {
                throw new Exception("Пользователь " + a_UserName + " не найден!");
            }
        }
        /// <summary>Обновление фасада</summary>
        public bool f_Update(Cl_User a_Doctor, Cl_MedicalCard a_MedCard, DateTime?a_DateStart = null, DateTime?a_DateEnd = null)
        {
            if (a_Doctor == null)
            {
                MonitoringStub.Error("Error_SessionFacade_Update", "Не указан доктор", null, null, null);
                return(false);
            }
            if (a_MedCard == null)
            {
                MonitoringStub.Error("Error_SessionFacade_Update", "Не указана медкарта", null, null, null);
                return(false);
            }
            p_Doctor = a_Doctor;

            p_Patient                = new Cl_User();
            p_Patient.p_UserID       = a_MedCard.p_PatientID;
            p_Patient.p_UserSurName  = a_MedCard.p_PatientSurName;
            p_Patient.p_UserName     = a_MedCard.p_PatientName;
            p_Patient.p_UserLastName = a_MedCard.p_PatientLastName;
            p_Patient.p_Sex          = a_MedCard.p_PatientSex;
            p_Patient.p_DateBirth    = a_MedCard.p_PatientDateBirth;
            p_DateStart              = a_DateStart;
            p_DateEnd                = a_DateEnd;
            p_MedicalCard            = a_MedCard;
            return(true);
        }
        public async Task <JsonResult> f_GetRolesForUser(string p_UserName)
        {
            Cl_User user = await m_UserManager.FindByNameAsync(p_UserName);

            IList <string> rolesUser = await m_UserManager.GetRolesAsync(user);

            List <ListInRoles> InRoles = new List <ListInRoles>();

            foreach (Cl_Role role in m_RoleManager.Roles)
            {
                ListInRoles inRole = new ListInRoles();
                inRole.p_RoleName = role.Name;
                foreach (string roleUser in rolesUser)
                {
                    if (roleUser == role.Name)
                    {
                        inRole.p_InRole = true;
                        break;
                    }
                }
                InRoles.Add(inRole);
            }

            var data   = InRoles.ToList().AsQueryable();
            var result = new {
                user  = p_UserName,
                roles = (from host in data
                         select new {
                    roleName = host.p_RoleName,
                    inRole = host.p_InRole
                }).ToArray()
            };

            return(Json(result));
        }
 /// <summary>Установка пользователя</summary>
 public void f_SetDoctor(Cl_User a_User)
 {
     p_ClinicName     = a_User.p_ClinicName;
     p_DoctorID       = a_User.p_UserID;
     p_DoctorSurName  = a_User.p_UserSurName;
     p_DoctorName     = a_User.p_UserName;
     p_DoctorLastName = a_User.p_UserLastName;
 }
Beispiel #7
0
 /// <summary>Установка пациента</summary>
 public void f_SetPatient(Cl_User a_User)
 {
     p_PatientID        = a_User.p_UserID;
     p_PatientSurName   = a_User.p_UserSurName;
     p_PatientName      = a_User.p_UserName;
     p_PatientLastName  = a_User.p_UserLastName;
     p_PatientSex       = a_User.p_Sex;
     p_PatientDateBirth = a_User.p_DateBirth;
 }
        /// <summary>Инициализация фасада</summary>
        public bool f_Init(Cl_User a_Doctor, Cl_MedicalCard a_MedCard, DateTime?a_DateStart = null, DateTime?a_DateEnd = null)
        {
            m_IsInit = f_Update(a_Doctor, a_MedCard, a_DateStart, a_DateEnd);

            if (p_SessionID == null || p_SessionID == Guid.Empty)
            {
                p_SessionID = Guid.NewGuid();
            }

            return(m_IsInit);
        }
Beispiel #9
0
        public async Task <ActionResult> f_GetUser()
        {
            IQueryable <Cl_User> users = m_AppDbContext.p_Users;
            Cl_User user = await users.FirstOrDefaultAsync(x => x.UserName == User.Identity.Name);

            if (user != null)
            {
                return(Json(new { p_Name = user.f_GetInitials(), p_Mobile = user.p_Mobile, p_Email = user.p_Email }));
            }
            else
            {
                return(Json(new { error = "Пользователь не найден!" }));
            }
        }
        public async Task f_CreateUser(string p_UserName, string p_Password, string p_Name, string p_SurName, string p_LastName, string p_Email, string p_Mobile, string p_Comment, DateTime?p_Birthday, string p_Address, bool p_IsLockedOut = false, bool p_IsTax = false)
        {
            Cl_User user = new Cl_User {
                Email     = p_Email, UserName = p_UserName, p_CreateDate = DateTime.Now, EmailConfirmed = true,
                p_SurName = p_SurName, p_Name = p_Name, p_LastName = p_LastName,
                p_Mobile  = p_Mobile, p_Comment = p_Comment, p_Birthday = p_Birthday, p_Address = p_Address, p_IsLockedOut = p_IsLockedOut
            };
            var result = await m_UserManager.CreateAsync(user, p_Password);

            if (!result.Succeeded)
            {
                throw new Exception("Не удалось создать пользователя." + result.Errors.FirstOrDefault()?.Description);
            }
        }
        private async Task LoadSharedKeyAndQrCodeUriAsync(Cl_User user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey        = FormatKey(unformattedKey);
            AuthenticatorUri = GenerateQrCodeUri(user.Email, unformattedKey);
        }
        private bool f_InitSession(string[] args)
        {
            Cl_User user = new Cl_User();

            user.p_ClinicName   = args[0];
            user.p_UserID       = int.Parse(args[1]);
            user.p_UserSurName  = args[2];
            user.p_UserName     = args[3];
            user.p_UserLastName = args[4];
            user.p_Permission   = new Cl_UserPermission(args[5]);
            int patientId = 0;

            if (int.TryParse(args[7], out patientId))
            {
                var medCard = Cl_MedicalCardsFacade.f_GetInstance().f_GetMedicalCard(args[6], patientId);
                if (medCard != null)
                {
                    if (user.p_Permission.p_Role == E_Roles.Assistant)
                    {
                        user.p_ParentUser = new Cl_User();
                        user.p_ParentUser.p_ClinicName   = user.p_ClinicName;
                        user.p_ParentUser.p_UserID       = int.Parse(args[10]);
                        user.p_ParentUser.p_UserSurName  = args[11];
                        user.p_ParentUser.p_UserName     = args[12];
                        user.p_ParentUser.p_UserLastName = args[13];
                    }

                    if (user.p_Permission.p_Role == E_Roles.Inspector)
                    {
                        return(Cl_SessionFacade.f_GetInstance().f_Init(user, medCard, DateTime.Parse(args[8]), DateTime.Parse(args[9])));
                    }
                    else
                    {
                        return(Cl_SessionFacade.f_GetInstance().f_Init(user, medCard));
                    }
                }
                else
                {
                    MonitoringStub.Error("Error_AppInit", "Не найдена медицинская карта", null, null, null);
                    return(false);
                }
            }
            else
            {
                MonitoringStub.Error("Error_AppInit", "Не верно указан Id пациента", null, null, null);
                return(false);
            }
        }
Beispiel #13
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    throw new ApplicationException("Error loading external login information during confirmation.");
                }
                var user = new Cl_User {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(Url.GetLocalUrl(returnUrl)));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ReturnUrl = returnUrl;
            return(Page());
        }