public ActionResult Index(RegisterDetails RegisterDetails)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                RegisterManager.MapRegisterDetail(RegisterDetails);
                if (RegisterManager.Validate())
                {
                    if (PortalSettings.UserRegistration != (int)Globals.PortalRegistrationType.NoRegistration)
                    {
                        actionResult = RegisterManager.CreateUser(RegisterDetails);
                    }
                    else
                    {
                        actionResult.AddError("Registration_NotAllowed", "User registration is not allowed.");
                    }
                }
                else
                {
                    if (RegisterManager.CreateStatus != UserCreateStatus.AddUser)
                    {
                        actionResult.AddError("Registration_Failed", UserController.GetUserCreateStatus(RegisterManager.CreateStatus));
                    }
                }
            }
            catch (Exception ex)
            {
                actionResult.AddError("Register_Error", ex.Message);
            }
            return(actionResult);
        }
Ejemplo n.º 2
0
        public bool Register(RegisterDetails input)
        {
            if (input == null)
            {
                return(false);
            }

            using (var context = new ShopContext())
            {
                User user = new User()
                {
                    FirstName       = input.FirstName,
                    LastName        = input.LastName,
                    Phone           = input.Phone,
                    Address         = input.Address,
                    ClosestBranchID = input.ClosestBranchID,
                    Username        = input.Username,
                    Password        = convertToMd5(input.Password),
                    IsAdmin         = 0
                };

                try
                {
                    context.Users.Add(user);
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Register(LoginPageModel loginModel)
        {
            RegisterDetails registerDetails = loginModel.RegisterDetails;

            try
            {
                AppUser user = await _userManager.FindByNameAsync(registerDetails.Username);

                if (user == null)
                {
                    user = new AppUser()
                    {
                        UserName    = registerDetails.Username,
                        FirstName   = registerDetails.FirstName,
                        LastName    = registerDetails.LastName,
                        Email       = registerDetails.Email,
                        DateOfBirth = registerDetails.DateOfBirth
                    };


                    var accountCreation = _userManager.CreateAsync(user, registerDetails.Password);

                    Task.WaitAll(accountCreation);
                    if (accountCreation.Result.Succeeded)
                    {
                        var accountStatsCreation = CreateAccountStats(user);
                        var emailConfirmation    = SendEmailConfirmation(user);

                        Task.WaitAll(accountStatsCreation, emailConfirmation);
                        if (accountStatsCreation.Result && emailConfirmation.Result)
                        {
                            loginModel.Notification = new AlertNotification(NotificationType.Success, "User-Registration Complete! An email has been sent to your email please confirm the verification.");
                            return(View("Index", loginModel));
                        }
                        //TODO: Add somekind of log just in-case the AccountStats somehow fail.
                        else
                        {
                            loginModel.Notification = new AlertNotification(NotificationType.Error, $"Failed to Create Account Relations: Please Contact Support!");
                            return(View("Index", loginModel));
                        }
                    }
                    else
                    {
                        loginModel.Notification = new AlertNotification(NotificationType.Error, $"Failed to Create Account: Please Contact Support!");
                        return(View("Index", loginModel));
                    }
                }
                else
                {
                    loginModel.Notification = new AlertNotification(NotificationType.Error, $"An account has already been registered with those details.");
                    return(View("Index", loginModel));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public async Task SaveUserDetails(RegisterViewModel registerViewModel)
        {
            if (registerViewModel.Id == Guid.Empty)
            {
                var             Id          = Guid.NewGuid();
                RegisterDetails userDetails = new RegisterDetails()
                {
                    Id        = Id,
                    FirstName = registerViewModel.FirstName,
                    LastName  = registerViewModel.LastName,
                    Email     = registerViewModel.Email,
                    Password  = registerViewModel.Password,
                };
                using (var context = new HealthDbContext(_dbContextOptions))
                {
                    context.RegisterDetails.Add(userDetails);
                    await context.SaveChangesAsync();
                }
            }
            else
            {
                using (var context = new HealthDbContext(_dbContextOptions))
                {
                    RegisterDetails userDetails = await context.RegisterDetails.FindAsync(registerViewModel.Id);

                    userDetails.FirstName = registerViewModel.FirstName;
                    userDetails.LastName  = registerViewModel.LastName;
                    userDetails.Email     = registerViewModel.Email;
                    userDetails.Password  = registerViewModel.Password;
                    await context.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 5
0
 public IActionResult Register(RegisterDetails model)
 {
     if (ModelState.IsValid)
     {
         return(View());
     }
     return(View());//error view
 }
Ejemplo n.º 6
0
 private bool CheckInputValid(RegisterDetails userInput)
 {
     return(userInput.Address == null ||
            userInput.FirstName == null ||
            userInput.LastName == null ||
            userInput.Password == null ||
            userInput.Phone == null || userInput.Username == null);
 }
Ejemplo n.º 7
0
        public ActionResult Register(RegisterDetails details)
        {
            if (userService.Register(details))
            {
                return(Json(true));
            }

            return(Json(false));
        }
Ejemplo n.º 8
0
        public IActionResult Register(RegisterDetails details)
        {
            if (userService.Register(details))
            {
                return(Ok());
            }

            return(StatusCode(500));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Register([FromBody] RegisterDetails details)
        {
            var u = await this._usersService.FindByEmail(details.Email);

            if (u != null)
            {
                return(BadRequest(new { Message = "Korisnik već postoji." }));
            }

            Models.User user = new Models.User()
            {
                CompanyName      = details.CompanyName,
                Email            = details.Email,
                ClientId         = Guid.NewGuid().ToString("N").ToLower(),
                Contact          = details.Contact,
                IsEmailConfirmed = false,
                Password         = SecurityUtils.EncryptPassword(details.Password),
                Phone            = details.Phone,
                Roles            = new string[] { "User" }
            };

            Models.User createdUser = await _usersService.CreateNew(user);

            if (createdUser == null)
            {
                _logger.LogInformation($"Could not register ({details.Email})");
                return(StatusCode(400, new { Message = "Došlo je do pogreške" }));
            }
            JWTBuilder jwtBuild   = new JWTBuilder(createdUser.Email, createdUser.ClientId, _jwtOptions, createdUser.Roles);
            string     encodedJwt = jwtBuild.GetJWT();

            var userProfile = new
            {
                ClientId = createdUser.ClientId,
                Email    = createdUser.Email
            };

            // Serialize and return the response
            var tokenWrapper = new
            {
                token = encodedJwt,
                user  = userProfile
            };

            //Response.Cookies.Append(
            //  "refreshToken",
            //  "testRefreshTokenContent",
            //  new CookieOptions()
            //  {
            //    HttpOnly = true
            //  });

            var json = JsonConvert.SerializeObject(tokenWrapper, _serializerSettings);

            return(Ok(tokenWrapper));
        }
Ejemplo n.º 10
0
        void RegisterAccount(RegisterDetails registerDetails)
        {
            var request = new RegisterPlayFabUserRequest
            {
                Email    = registerDetails.Email,
                Password = registerDetails.Password,
                Username = registerDetails.Username
            };

            PlayFabClientAPI.RegisterPlayFabUser(request, RegisterSuccess, RegisterFailure);
        }
Ejemplo n.º 11
0
 private void ButtonAddDetail_Click(object sender, RoutedEventArgs e)
 {
     var item = new RegisterDetails
     {
         Npp = model.Details.Any() ? model.Details.Max(x => x.Npp) + 1 : 1,
         DetailType = model.DetailTypesList.FirstOrDefault(x => x.Id == 0),
         WorkPlace = model.WorkPlacesList.FirstOrDefault(x => x.Id == 0),
         //DetailType = Singleton<ReferencesCollection>.Instance.SpDetailTypesCollection.FirstOrDefault(x => x.Id == 0),
         //WorkPlace = Singleton<ReferencesCollection>.Instance.WorkPlacesCollection.FirstOrDefault(x => x.Id == 0),
         Parent = model.RegisterItem
     };
     model.Details.Add(item);
 }
Ejemplo n.º 12
0
        public RegisterDetails GetDal_RegisterDetails(bool withTransaction)
        {
            RegisterDetails objRegisterDetails = null;

            if (withTransaction)
            {
                objRegisterDetails = new RegisterDetails(_transaction);
            }
            else
            {
                objRegisterDetails = new RegisterDetails(_connectionString);
            }
            return(objRegisterDetails);
        }
Ejemplo n.º 13
0
            public static ActionResult CreateUser(RegisterDetails RegisterDetails)
            {
                ActionResult actionResult = new ActionResult();

                User.Membership.Approved = PortalSettings.Current.UserRegistration == (int)Globals.PortalRegistrationType.PublicRegistration;
                CreateStatus             = UserController.CreateUser(ref User);
                DataCache.ClearPortalUserCountCache(PortalSettings.Current.PortalId);

                try
                {
                    if (CreateStatus == UserCreateStatus.Success)
                    {
                        ////Assocate alternate Login with User and proceed with Login
                        //if (!String.IsNullOrEmpty(AuthenticationType))
                        //{
                        //    AuthenticationController.AddUserAuthentication(User.UserID, AuthenticationType, UserToken);
                        //}

                        ActionResult result = CompleteUserCreation(CreateStatus, User, true, !(HttpContext.Current.Request.IsAuthenticated && PortalSecurity.IsInRole(PortalSettings.Current.AdministratorRoleName)) && !(HttpContext.Current.Request.IsAuthenticated && (User.UserID == (PortalController.Instance.GetCurrentSettings() as PortalSettings).UserInfo.UserID)));
                        if (result.IsSuccess)
                        {
                            if (string.IsNullOrEmpty(result.Message))
                            {
                                IDictionary <string, object> dynObjects = new ExpandoObject() as IDictionary <string, object>;
                                dynObjects.Add("RedirectURL", GetRedirectUrl());
                                actionResult.Data = dynObjects;
                            }
                            actionResult.Message = result.Message;
                        }
                        else
                        {
                            string errorMessage = string.Empty;
                            foreach (KeyValuePair <string, Exception> error in result.Errors)
                            {
                                errorMessage = error.Value.ToString();
                            }
                            actionResult.AddError("RegisterManager.CompleteUserCreation", errorMessage);
                        }
                    }
                    else
                    {
                        actionResult.AddError("RegisterManager.CreateUser", UserController.GetUserCreateStatus(CreateStatus));
                    }
                }
                catch (Exception exc) //Module failed to load
                {
                    Exceptions.ProcessModuleLoadException(null, exc);
                }
                return(actionResult);
            }
Ejemplo n.º 14
0
            //static string _UserToken;
            //protected static string UserToken
            //{
            //    get
            //    {
            //        return "";
            //    }
            //    set
            //    {
            //        _UserToken = value;
            //    }
            //}

            //static string _AuthenticationType;
            //protected static string AuthenticationType
            //{
            //    get
            //    {
            //        return "";
            //    }
            //    set
            //    {
            //        _AuthenticationType = value;
            //    }
            //}

            internal static void MapRegisterDetail(RegisterDetails Request)
            {
                UserModuleBase userModuleBase = new UserModuleBase();

                User                            = userModuleBase.UserInfo;
                User.Username                   = !string.IsNullOrEmpty(Request.UserName) ? Request.UserName : null;
                User.Email                      = !string.IsNullOrEmpty(Request.Email) ? Request.Email : null;
                User.DisplayName                = !string.IsNullOrEmpty(Request.DisplayName) ? Request.DisplayName : null;
                User.Membership.Password        = !string.IsNullOrEmpty(Request.Password) ? Request.Password : null;
                User.Membership.PasswordConfirm = !string.IsNullOrEmpty(Request.ConfirmPassword) ? Request.ConfirmPassword : null;
                User.PortalID                   = PortalSettings.Current.PortalId;
                User.Profile.PreferredLocale    = Thread.CurrentThread.CurrentUICulture.ToString();
                //Update DisplayName to conform to Format
                if (!string.IsNullOrEmpty(PortalSettings.Current.Registration.DisplayNameFormat))
                {
                    User.UpdateDisplayName(PortalSettings.Current.Registration.DisplayNameFormat);
                }
            }
Ejemplo n.º 15
0
        public bool Register(RegisterDetails UserInput)
        {
            if (UserInput is null || CheckInputValid(UserInput))
            {
                return(false);
            }
            using (var Context = new CoronaPageContext())
            {
                User newUser = new User()
                {
                    Address   = UserInput.Address,
                    FirstName = UserInput.FirstName,
                    IsAdmin   = 0,
                    LastName  = UserInput.LastName,
                    Password  = convertToMd5(UserInput.Password),
                    Phone     = UserInput.Phone,
                    Username  = UserInput.Username
                };

                Context.Users.Add(newUser);
                Context.SaveChanges();
            }
            return(true);
        }