public JsonResult UpdateAppUserInformation(AppUserInformationModel appUserInformationModel)
        {
            Response <bool> response = new Response <bool>();

            appUserProvider = new AppUserProvider();

            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);

                appUserInformationModel.TokenKey = appUserModel.TokenKey;

                appUserInformationModel.AppUserId = appUserModel.AppUser.AppUserId;

                InfrastructureModel <bool> infrastructureModel = appUserProvider.Update(appUserInformationModel);

                response = new Response <bool>
                {
                    Data    = infrastructureModel.ResultStatus,
                    Message = "success",
                    Status  = infrastructureModel.ResultStatus,
                };
            }
            return(Json(response));
        }
        public JsonResult Login(AppUserLoginModel appUserLoginModel)
        {
            Response response = new Response();

            tokenProvider = new TokenProvider();
            try
            {
                appUserProvider = new AppUserProvider();

                AppUserModel appuserModel = appUserProvider.GetLoginUser(appUserLoginModel).ResultModel;

                if (appuserModel != null)
                {
                    SessionExtension.Set <AppUserModel>(HttpContext.Session, "Login", appuserModel);

                    response = new Response()
                    {
                        Message     = "success",
                        Status      = true,
                        RedirectUrl = Url.Action("Index", "Home")
                    };
                }
            }
            catch (Exception ex)
            {
                response = new Response()
                {
                    Message = "Fail",
                    Status  = false,
                };
            }
            return(Json(response));
        }
        public JsonResult ChangePassword(AppUserLoginModel appUserLoginModel)
        {
            Response <bool> response = new Response <bool>();

            appUserProvider = new AppUserProvider();

            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);

                appUserLoginModel.TokenKey  = appUserModel.TokenKey;
                appUserLoginModel.AppUserId = appUserModel.AppUser.AppUserId;

                InfrastructureModel <bool> infrastructureModel = appUserProvider.ChangePassword(appUserLoginModel);

                response = new Response <bool>()
                {
                    Data    = infrastructureModel.ResultModel,
                    Message = infrastructureModel.Message,
                    Status  = true,
                    Refresh = true
                };
            }
            return(Json(response));
        }
 public LoginPage()
 {
     InitializeComponent();
     appUserProvider   = new AppUserProvider();
     btnLogin.Clicked += BtnLogin_Clicked;
     NavigationPage.SetHasNavigationBar(this, false);
 }
        public async Task <UpdateResult> AddProvider(string id, AppUserProvider provider)
        {
            var query = _clearBuilder
                        .Eq(x => x.Id, id)
                        .UpdateAddToSet(x => x.ConnectedProviders, provider);

            await UpdateByQuery(query);

            return(new UpdateResult.Acknowledged(1, 1, id));
        }
        public JsonResult ResetAllInformation()
        {
            Response <bool> response = new Response <bool>();

            appUserProvider = new AppUserProvider();
            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);

                InfrastructureModel <bool> infrastructureModel = appUserProvider.ResetAllInformationAppUser(appUserTokenModel);

                response = new Response <bool>
                {
                    Data    = infrastructureModel.ResultStatus,
                    Message = infrastructureModel.Message,
                    Status  = infrastructureModel.ResultStatus,
                };
            }
            return(Json(response));
        }
        public JsonResult GetAppUserInformation(AppUserLoginModel appUserLoginModel)
        {
            Response <AppUserInformationModel> response = new Response <AppUserInformationModel>();

            appUserProvider = new AppUserProvider();
            AppUserModel appUserModel = SessionExtension.GetSessionUser(HttpContext.Session);

            if (appUserModel != null)
            {
                AppUserModel appUserTokenModel = SessionExtension.GetSessionUser(HttpContext.Session);
                InfrastructureModel <AppUserInformationModel> appUserInformationModel = appUserProvider.GetById(new AppUserLoginModel()
                {
                    AppUserId = appUserModel.AppUser.AppUserId, TokenKey = appUserModel.TokenKey
                });
                response = new Response <AppUserInformationModel>()
                {
                    Data    = appUserInformationModel.ResultModel,
                    Message = "succes",
                    Status  = true
                };
            }
            return(Json(response));
        }
        /// <summary>
        /// Invite new user or connect exists
        /// </summary>
        /// <param name="model">Provider create user model</param>
        /// <returns>UserDisplayModel</returns>
        public async Task <UserDisplayModel> InviteUser(ProviderUserCreateModel model)
        {
            var currentUser = await GetCurrentUser();

            if (!await _providerRepository.ExistsWithOwner(model.ProviderId, currentUser.Id))
            {
                throw new AccessDeniedException(currentUser.Id, typeof(AppUser));
            }

            if (model.Roles == null || !model.Roles.Any())
            {
                throw new AccessDeniedException("", typeof(AppUser));
            }

            model.Roles = model.Roles.Select(x => x.ToUpper()).ToList();

            var pShort = await _providerRepository.GetShortById(model.ProviderId);

            var roles = await _providerRepository.GetRolesById(model.ProviderId);

            var rolesToUse = roles.Where(x => model.Roles.Contains(x.Name)).ToList();

            var existsUser = await _appUserRepository.FindByEmailAsync(model.Email.ToLower(), new System.Threading.CancellationToken());

            if (existsUser == null)
            {
                existsUser = new AppUser
                {
                    Email     = model.Email.ToLower(),
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Tels      = new List <MRUserTel>(),
                    Status    = UserStatus.Invited,
                    UserName  = model.Email.ToLower(),
                };

                existsUser.ConnectedProviders = new List <AppUserProvider>
                {
                    new AppUserProvider
                    {
                        ProviderId   = pShort.Id,
                        ProviderName = pShort.Name,
                        Roles        = rolesToUse,
                        Metadata     = new List <AppUserProviderMeta>(),
                        UpdatedTime  = DateTime.UtcNow
                    }
                };

                var insertResult = await _appUserManager.CreateAsync(existsUser);

                if (!insertResult.Succeeded)
                {
                    throw new MRException();
                }

                await _appUserManager.AddToRoleAsync(existsUser, AppUserRoleList.USER);
            }
            else if (!existsUser.ConnectedProviders.Any(x => x.ProviderId == pShort.Id))
            {
                AppUserProvider provider = new AppUserProvider
                {
                    ProviderId   = pShort.Id,
                    Metadata     = new List <AppUserProviderMeta>(),
                    ProviderName = pShort.Name,
                    Roles        = rolesToUse,
                    UpdatedTime  = DateTime.UtcNow
                };

                if ((await _appUserRepository.AddProvider(existsUser.Id, provider)).ModifiedCount != 1)
                {
                    throw new MRException();
                }
            }
            else
            {
                throw new MRException();
            }

            Infrastructure.Model.Template.User.ProviderInviteTemplate templateModel = new Infrastructure.Model.Template.User.ProviderInviteTemplate
            {
                FirstName    = existsUser.FirstName,
                LastName     = existsUser.LastName,
                LoginLink    = "https://google.com",
                ProviderName = pShort.Name
            };

            var email = await _templateParser.Render("Email", "ProviderInvite", templateModel);

            await _emailSendTaskRepository.InsertEmail(existsUser.Email, "Mad Rat Studio invite", email, Infrastructure.Entities.Tasks.EmailTaskBot.MadRatBot);

            return(_mapper.Map <UserDisplayModel>(existsUser));
        }
Example #9
0
        /// <summary>
        /// Login approve logic
        /// </summary>
        /// <param name="context">Context</param>
        /// <param name="token">User`s short live token</param>
        /// <returns></returns>
        public async Task <ApproveLogin> ProviderApproveLogin(HttpContext context, string token, string fingerprint)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                throw new MRSystemException();
            }

            var challengeResult = await _challengeShortLiveToken(token, fingerprint);

            if (!challengeResult.IsSuccess)
            {
                throw new MRSystemException(challengeResult.Error.Message);
            }

            var user = await _appUserRepository.Get(challengeResult.UserId);

            if (user == null)
            {
                throw new EntityNotFoundException(challengeResult.UserId, typeof(AppUser));
            }

            if (user.Isblocked)
            {
                throw new MRSystemException("User blocked");
            }

            var targetUProvider = user.ConnectedProviders.FirstOrDefault(x => x.ProviderId == challengeResult.ProviderId);

            if (targetUProvider == null)
            {
                targetUProvider = new AppUserProvider
                {
                    ProviderId   = challengeResult.ProviderId,
                    ProviderName = challengeResult.Provider.Name,
                    Roles        = challengeResult.Provider.Roles?.Where(x => x.IsDefault).ToList() ?? new List <ProviderRole>(),
                    UpdatedTime  = DateTime.UtcNow,
                    Metadata     = new List <AppUserProviderMeta>
                    {
                        _createMeta(context)
                    }
                };

                await _appUserRepository.AddProvider(user.Id, targetUProvider);
            }
            else
            {
                await _appUserRepository.AddProviderMeta(user.Id, targetUProvider.ProviderId, _createMeta(context));
            }

            var result = new ApproveLogin
            {
                AvatarUrl = user.Image?.Url,
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Id        = user.Id,
                Roles     = targetUProvider.Roles.Select(x => x.Name).ToList(),
            };

            return(result);
        }