Пример #1
0
        public void ClearModelStateOnAdd(ModelStateDictionary modelState, UserNewModel model)
        {
            modelState.Clear();

            #region CNP

            if (!Validation.CNPValidator(model.CNP))
            {
                modelState.AddModelError("New.CNP", Resource.InvalidCNP);
            }
            else if (_usersRepository.NotUniqueCNP(model.CNP))
            {
                modelState.AddModelError("New.CNP", Resource.NotUniqueCNP);
            }

            #endregion

            #region User State

            if (model.RoleBtnList != null && model.RoleBtnList.SelectedValues != null)
            {
                var selected = model.RoleBtnList.SelectedValues;
                if (selected == UserRoles.Patient && (model.State == null || model.State.SelectedValues == null))
                {
                    modelState.AddModelError("New.State", Resource.RequiredField);
                }
            }

            #endregion
        }
Пример #2
0
        public async Task <ResponseModel> CreateUser(UserNewModel appUser)
        {
            try
            {
                var resp = await _userManager.CreateAsync(new AppUser { UserName = appUser.UserName, Email = appUser.Email, PhoneNumber = appUser.Phone, LockoutEnabled = false, PhoneNumberConfirmed = true, TwoFactorEnabled = false }, appUser.Password);

                if (resp.Succeeded)
                {
                    return new ResponseModel {
                               Status = HttpStatusCode.OK, Success = "User has created"
                    }
                }
                ;
                else
                {
                    return new ResponseModel {
                               Status = HttpStatusCode.BadRequest, Errors = resp.Errors.Select(x => x.Code + "-" + x.Description)
                    }
                };
            }
            catch (System.Exception ex)
            {
                return(new ResponseModel {
                    Status = HttpStatusCode.InternalServerError, Errors = new[] { "Exception:" + ex.Message }
                });
            }
        }
Пример #3
0
 public static void ToAddressDomainModel(this UserNewModel viewModel, AddressModel domainModel)
 {
     domainModel.CountryId = viewModel.Countries != null && viewModel.Countries.SelectedValues != null
         ? viewModel.Countries.SelectedValues.Value
         : 0;
     domainModel.PhysicalAddress = viewModel.PhysicalAddress;
 }
Пример #4
0
        public UserNewModel GetNewForm(UsersSettings settings)
        {
            var model = new UserNewModel();

            var userData = settings.UserData;

            model.RoleBtnList = new BsSelectList <UserRoles?>();

            if (userData.IsDoctor)
            {
                model.RoleBtnList.ItemsFromEnum(typeof(UserRoles), UserRoles.Admin, UserRoles.All);
            }
            else
            {
                model.RoleBtnList.ItemsFromEnum(typeof(UserRoles), UserRoles.All);
            }
            model.RoleBtnList.SelectedValues = UserRoles.Patient;

            model.GenderBtnList = new BsSelectList <GenderEnum?>();
            model.GenderBtnList.ItemsFromEnum(typeof(GenderEnum), GenderEnum.Both);
            model.GenderBtnList.SelectedValues = GenderEnum.Male;


            model.State       = new BsSelectList <int?>();
            model.State.Items = db.UsersStates.Select(x => new BsSelectListItem
            {
                Text  = x.Code,
                Value = x.Id.ToString()
            }).ToList();

            return(model);
        }
Пример #5
0
 public static void ToUserProfileDomainModel(this UserNewModel viewModel, UserProfileModel domainModel)
 {
     domainModel.Id_Citizenship = viewModel.Citizenship != null && viewModel.Citizenship.SelectedValues != null
         ? viewModel.Citizenship.SelectedValues.Value
         : 0;
     domainModel.Id_State = viewModel.State != null && viewModel.State.SelectedValues != null
         ? (int?)viewModel.State.SelectedValues.Value
         : null;
     domainModel.PhoneNumber = viewModel.PhoneNumber;
     domainModel.Profession  = viewModel.Profession;
     domainModel.Gender      = viewModel.GenderBtnList != null && viewModel.GenderBtnList.SelectedValues != null
         ? (int)viewModel.GenderBtnList.SelectedValues
         : 0;
     domainModel.BirthDay = viewModel.BirthDayPicker.DateValue.HasValue
         ? viewModel.BirthDayPicker.DateValue.Value
         : DateTime.MinValue;
 }
Пример #6
0
        public async Task <IActionResult> CreateUser([FromBody] UserNewModel objInput)
        {
            //var IsValidClaim = HttpContext.ValidatePermission("2");
            //if (!IsValidClaim)
            //    return Unauthorized("you don't have permission");


            var blUser = await _userManager.CreateUser(objInput);

            if (blUser.Status == HttpStatusCode.OK)
            {
                return(Ok(blUser));
            }
            else
            {
                return(BadRequest(blUser));
            }
        }
Пример #7
0
        public static void ToUserDomainModel(this UserNewModel viewModel, UserModel domainModel)
        {
            domainModel.Firstname = viewModel.Firstname;
            domainModel.Lastname  = viewModel.Lastname;
            domainModel.CNP       = viewModel.CNP;

            var currentSalt       = ConfigurationManager.AppSettings["authSalt"];
            var encryptedPassword = viewModel.Password.Encrypt(currentSalt);

            domainModel.Password = encryptedPassword;

            domainModel.Enabled = true;
            if (viewModel.RoleBtnList != null && viewModel.RoleBtnList.SelectedValues != null)
            {
                var selected = viewModel.RoleBtnList.SelectedValues;
                domainModel.IsAdmin   = selected == UserRoles.Admin;
                domainModel.IsDoctor  = selected == UserRoles.Doctor;
                domainModel.IsPatient = selected == UserRoles.Patient;
            }
            domainModel.SidebarMode = true;
            domainModel.Email       = viewModel.Email;
        }
Пример #8
0
        public async Task <IActionResult> Register([FromBody] UserNewModel model)
        {
            var response = await user.Register(model);

            return(StatusCode(response.Code, response.Message));
        }
Пример #9
0
        public async Task <BaseServiceResponse> Register(UserNewModel model)
        {
            var response = new BaseServiceResponse();

            if (model.Username == null || model.Password == null || model.Email == null)
            {
                return(response);
            }
            model.Username = model.Username.ToLower();
            model.Email    = model.Email.ToLower();

            //Convert to new User Model
            var userModel = new UserModel()
            {
                Username = model.Username.ToLower(),
                Password = model.Password,
                Email    = model.Email.ToLower(),
                Meta     = new UserMetaModel()
                {
                    PrimaryUse = model.PrimaryUse,
                    Referral   = model.Referral
                }
            };

            var hash = hasher.Hash(userModel.Password);

            userModel.Password = hash.Hash;
            userModel.Salt     = hash.Salt;

            var exists = await db.Exists(userModel);

            if (exists.Email == model.Email)
            {
                return new BaseServiceResponse()
                       {
                           Code = 409, Message = "Email already in use"
                       }
            }
            ;
            else if (exists.Username == model.Username)
            {
                return new BaseServiceResponse()
                       {
                           Code = 409, Message = "Username already in use"
                       }
            }
            ;

            try
            {
                await db.InsertAsync(userModel);
            }
            catch (PostgresDuplicateValueException e)
            {
                var sentry = new SentryEvent(e);
                await raven.CaptureNetCoreEventAsync(sentry);

                //Should not get this exception
                throw e;
            }
            catch (Exception e)
            {
                var sentry = new SentryEvent(e);
                await raven.CaptureNetCoreEventAsync(sentry);
            }

            AppTask.Forget(() => email.SendWelcomeTo(new WelcomeModel()
            {
                Address = userModel.Email,
                Subject = "Welcome to Aliseeks",
                User    = userModel.Username
            }));

            return(response);
        }