Пример #1
0
        public object Any(ResetViewModel request)
        {
            ValidationResult validations = new ResetAccountValidator().Validate(request);

            if (!validations.IsValid)
            {
                request.ResponseResult.ResultStatus = ResultStatuses.Error;
                foreach (var item in validations.Errors)
                {
                    request.ResponseResult.Messages.Add(item.ErrorMessage);
                }

                return(request);
            }

            string de = request.Hash.Decrypt("hash");

            var userAuth = UserAuthRepository.GetUserAuthByUserName(de);

            if (userAuth != null)
            {
                UserAuthRepository.UpdateUserAuth(userAuth, userAuth, request.Password);
            }

            request.ResponseResult.ResultStatus = ResultStatuses.Success;
            request.ResponseResult.Messages.Clear();

            return(request);
        }
Пример #2
0
        public UserResponseBO Authenticate(UserBO userBO)
        {
            using (var db = new dbGSCasinoContext())
            {
                UserAuthRepository userAuthRepository = new UserAuthRepository();
                TblUserAuth        userAuth           = userAuthRepository.Get(userBO, db);

                UserInfoRepository userInfoRepository = new UserInfoRepository();
                TblUserInfo        userInfo           = userInfoRepository.Get(userAuth, db);

                UserWalletRepository userWalletRepository = new UserWalletRepository();
                List <UserWalletBO>  userWallet           = userWalletRepository.GetBO(userAuth, db);

                UserRoleRepository userRoleRepository = new UserRoleRepository();
                TblUserRole        userRole           = userRoleRepository.Get(userAuth, db);

                UserResponseBO userAuthResponse = new UserResponseBO();

                userAuthResponse.UserInfo   = userInfo;
                userAuthResponse.UserWallet = userWallet;
                userAuthResponse.UserAuth   = userAuth;
                userAuthResponse.UserRole   = userRole;

                return(userAuthResponse);
            }
        }
Пример #3
0
        public object Any(ResetPassword request)
        {
            var res  = new ResetPasswordResponse();
            var user = UserAuthRepository.GetUserAuthByUserName(request.Email);

            if (null == user)
            {
                res.Success = false;
                res.Message = "Invalid email address.";
                return(res);
            }

            var secret = Cache.Get <string>($"password:secret:{user.Email}");

            if (secret.IsNullOrEmpty() || !secret.Equals(request.Token))
            {
                res.Success = false;
                res.Message = "Reset window expired.";
                return(res);
            }

            UserAuthRepository.UpdateUserAuth(user, user, request.Password);
            Cache.Remove($"password:secret:{user.Email}");

            using (var service = ResolveService <AuthenticateService>())
            {
                return(service.Authenticate(new Authenticate
                {
                    provider = AuthenticateService.CredentialsProvider,
                    UserName = user.Email,
                    Password = request.Password
                }));
            }
        }
Пример #4
0
        public IUserAuth GetUserAuth(IAuthSession authSession, IAuthTokens tokens)
        {
            if (!string.IsNullOrEmpty(authSession.UserAuthId))
            {
                var userAuth = GetUserAuth(authSession.UserAuthId);
                if (userAuth != null)
                {
                    return(userAuth);
                }
            }

            if (!string.IsNullOrEmpty(authSession.UserAuthName))
            {
                var userAuth = GetUserAuthByUserName(authSession.UserAuthName);
                if (userAuth != null)
                {
                    return(userAuth);
                }
            }

            if (tokens == null || string.IsNullOrEmpty(tokens.Provider) || string.IsNullOrEmpty(tokens.UserId))
            {
                return(null);
            }

            var oAuthProvider = UserAuthDetailsRepository.Where(u => u.Provider == tokens.Provider && u.UserId == tokens.UserId)
                                .FirstOrDefault();

            if (oAuthProvider != null)
            {
                return(UserAuthRepository.GetById(oAuthProvider.UserAuthId));
            }
            return(null);
        }
Пример #5
0
        public void DeleteUserAuth(string userAuthId)
        {
            int userId = int.Parse(userAuthId);

            UserAuthRepository.Delete(userId);
            UserAuthDetailsRepository.Delete(UserAuthDetailsRepository.Where(u => u.UserAuthId == userId).SingleOrDefault());
        }
Пример #6
0
        public bool Create(UserBO userBO)
        {
            using (var db = new dbGSCasinoContext())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    UserInfoRepository userInfoRepository = new UserInfoRepository();
                    TblUserInfo        userInfo           = userInfoRepository.Create(userBO, db);

                    UserAuthRepository userAuthRepository = new UserAuthRepository();
                    TblUserAuth        userAuth           = userAuthRepository.Create(userBO, userInfo, db);

                    UserRoleRepository userRoleRepository = new UserRoleRepository();
                    userRoleRepository.Create(userAuth, db);

                    // CREATE USER WALLETS
                    UserWalletAppService userWallet = new UserWalletAppService();
                    userWallet.Create(userAuth, db);

                    transaction.Commit();

                    return(true);
                }
            }
        }
        public ActionResult SignUp(string name, string email, string password, string cpassword, string phone, string token, int permission)
        {
            var  mgr  = new UserAuthRepository();
            var  mgr2 = new AdminMembersRepository();
            User u    = mgr.AddUser(name, password, phone, email);

            mgr2.SetupMemberRel(token, u.Id, int.Parse(User.Identity.Name));
            return(RedirectToAction("Login", "Pages"));
        }
        public ActionResult ResetAuthPassword(string password, int userid)
        {
            var mgr  = new UserAuthRepository();
            var rmgr = new ResetPasswordRepository();

            mgr.AddAction(userid, "reset password", DateTime.Now);
            rmgr.DeleteToken(userid);
            mgr.UpdatePassword(password, userid);
            return(RedirectToAction("Login"));
        }
Пример #9
0
        public void SaveUserAuth(IUserAuth userAuth)
        {
            userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.CreatedDate == default(DateTime))
            {
                userAuth.CreatedDate = userAuth.ModifiedDate;
            }

            userAuth = UserAuthRepository.CreateUpdate(userAuth as JarsUserAuth, MODIEFIED_BY);
        }
Пример #10
0
        public UnitOfWork(IDbConnection connection,
                          IDbTransaction dbTransaction)
        {
            _connection    = connection;
            _dbTransaction = dbTransaction;

            DepartmentRepository = new DepartmentRepository(_connection, _dbTransaction);
            EmployerRepository   = new EmployerRepository(_connection, _dbTransaction);
            OccupationRepository = new OccupationRepository(_connection, _dbTransaction);
            UserAuthRepository   = new UserAuthRepository(_connection, _dbTransaction);
            UserRepository       = new UserRepository(_connection, _dbTransaction);
        }
Пример #11
0
        public IUserAuth CreateUserAuth(IUserAuth newUser, string password)
        {
            newUser.ValidateNewUser(password);

            AssertNoExistingUser(newUser);

            newUser.PopulatePasswordHashes(password);
            newUser.CreatedDate  = DateTime.UtcNow;
            newUser.ModifiedDate = newUser.CreatedDate;

            newUser = UserAuthRepository.CreateUpdate(new JarsUserAuth(newUser), MODIEFIED_BY);

            return(newUser);
        }
        public ActionResult SignUp(string name, string password, string phone, string email)
        {
            var    mgr = new UserAuthRepository();
            string onlyNumericNumber = Regex.Replace(phone, @"[^0-9]", "");
            User   u = mgr.AddUser(name, password, onlyNumericNumber, email);
            //EmailManager em = new EmailManager();
            //em.SendWelcomeEmail(name, email);
            SMSManager SMS     = new SMSManager();
            string     message = "Welcome to Expiration Tracking App! You've officially take the first step torward  the pleasure of sitting back knowing your expiration dates are handled. - Happy Tracking ;)";

            SMS.Notification(u.PhoneNumber, message);
            FormsAuthentication.SetAuthCookie(u.Id.ToString(), true);
            return(RedirectToAction("index", "portal"));
        }
Пример #13
0
        public object Any(ForgotPassword request)
        {
            var res  = new ForgotPasswordResponse();
            var user = UserAuthRepository.GetUserAuthByUserName(request.Email);

            if (null == user)
            {
                res.Success = false;
                res.Message = "Invalid email address.";
                return(res);
            }

            var secret = Regex.Replace(SessionExtensions.CreateRandomBase62Id(32), @"[^\w\d]", "",
                                       RegexOptions.IgnoreCase);
            var link    = $"{Configuration.Web.Domain}{Configuration.Web.PasswordResetLinkFormat.Fmt(user.Email, secret)}";
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(Configuration.Mail.From));
            message.To.Add(new MailboxAddress(user.Email));
            message.Subject = "[Derprecated] Password Reset";
            message.Body    = new TextPart("html")
            {
                Text =
                    $@"
                <html>
                    <head></head>
                    <body>
                        <p>
                            Click on the following link to reset your password:
                            <br/><br/>
                            <a href=""{
                        link}"">{link
                        }</a>
                            <br/><br/>
                            This link will expire in 4 hours.
                        </p>
                    </body>
                </html>
                "
            };

            Cache.Set($"password:secret:{user.Email}", secret, Expiration);
            SmtpClient.Send(message);

            res.Success = true;
            res.Message = null;

            return(res);
        }
Пример #14
0
        public IUserAuth UpdateUserAuth(IUserAuth existingUser, IUserAuth newUser)
        {
            newUser.ValidateNewUser();

            AssertNoExistingUser(newUser, existingUser);

            newUser.Id           = existingUser.Id;
            newUser.PasswordHash = existingUser.PasswordHash;
            newUser.Salt         = existingUser.Salt;
            newUser.CreatedDate  = existingUser.CreatedDate;
            newUser.ModifiedDate = DateTime.UtcNow;

            newUser = UserAuthRepository.CreateUpdate(new JarsUserAuth(newUser), MODIEFIED_BY);

            return(newUser);
        }
        public ActionResult Login(string email, string password)
        {
            var  mgr = new UserAuthRepository();
            User u   = mgr.GetUser(email, password);

            if (u == null)
            {
                return(View(true));
            }
            else
            {
                mgr.AddAction(u.Id, "Log In", DateTime.Now);
                FormsAuthentication.SetAuthCookie(u.Id.ToString(), true);
                return(RedirectToAction("index", "portal"));
            }
        }
        public ActionResult OrgSignUp(string name, string email, string phone, string password, string oname, string oemail, string oaddress, string ocity, string ostate, string ozip, string ophone, int year, IEnumerable <int> category)
        {
            var    mgr = new UserAuthRepository();
            string onlyNumericNumber = Regex.Replace(phone, @"[^0-9]", "");
            User   u = mgr.AddUser(name, password, onlyNumericNumber, email);
            //SMSManager SMS = new SMSManager();
            //string message = "Welcome to Expiration Reminder App! Thanks for setting up a new organization account with us and we look forward to working with you.";
            //SMS.Notification(u.PhoneNumber, message);
            Organization o = mgr.AddOrg(u.Id, oname, oaddress, oemail, ocity, ostate, ozip, ophone, year);

            mgr.CreateInitialUserOrdRel(o.Id, u.Id);
            foreach (int i in category)
            {
                mgr.CreateOrgReqItems(o.Id, i);
            }
            FormsAuthentication.SetAuthCookie(u.Id.ToString(), true);
            return(RedirectToAction("index", "portal"));
        }
 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
 {
     using (UserAuthRepository _repo = new UserAuthRepository())
     {
         var user = _repo.ValidateUser(context.UserName, context.Password);
         if (user == null)
         {
             context.SetError("invalid_grant", "Provided username and password is incorrect");
             return;
         }
         var identity = new ClaimsIdentity(context.Options.AuthenticationType);
         //identity.AddClaim(new Claim(ClaimTypes.Role, user.UserRoles));
         identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
         identity.AddClaim(new Claim("Email", user.Email));
         identity.AddClaim(new Claim("RoleId", user.UserRoleId.ToString()));
         context.Validated(identity);
     }
 }
Пример #18
0
        public IUserAuth GetUserAuthByUserName(string userNameOrEmail)
        {
            if (!hasInitSchema)
            {
                InitSchema();
            }

            if (userNameOrEmail == null)
            {
                return(null);
            }

            bool   isEmail       = userNameOrEmail.Contains("@");
            string lowerUserName = userNameOrEmail.ToLower();

            if (HostContext.GetPlugin <AuthFeature>()?.SaveUserNamesInLowerCase == true)
            {
                return(isEmail
                    ? UserAuthRepository.Where(u => u.Email == lowerUserName).FirstOrDefault()
                    : UserAuthRepository.Where(u => u.UserName == lowerUserName).FirstOrDefault());
            }

            // Try an exact search using index first
            JarsUserAuth userAuth = isEmail
                 ? UserAuthRepository.Where(u => u.Email == userNameOrEmail).FirstOrDefault()
                 : UserAuthRepository.Where(u => u.UserName == userNameOrEmail).FirstOrDefault();

            if (userAuth != null)
            {
                return(userAuth);
            }

            // Fallback to a non-index search if no exact match is found
            if (ForceCaseInsensitiveUserNameSearch)
            {
                userAuth = isEmail
                    ? UserAuthRepository.Where(u => u.Email == lowerUserName).FirstOrDefault()
                    : UserAuthRepository.Where(u => u.UserName == lowerUserName).FirstOrDefault();
            }

            return(userAuth);
        }
Пример #19
0
        public UserAuthResponse Authenticate(UserBO userBO)
        {
            using (var db = new dbWorldCCityContext())
            {
                UserAuthRepository userAuthRepository = new UserAuthRepository();
                TblUserAuth        userAuth           = userAuthRepository.Get(userBO, db);

                UserInfoRepository userInfoRepository = new UserInfoRepository();
                TblUserInfo        userInfo           = userInfoRepository.Get(userAuth, db);

                UserWalletRepository userWalletRepository = new UserWalletRepository();
                List <UserWalletBO>  userWallet           = userWalletRepository.GetBO(userAuth, db);

                UserAuthResponse userAuthResponse = new UserAuthResponse();

                userAuthResponse.UserInfo   = userInfo;
                userAuthResponse.UserWallet = userWallet;
                userAuthResponse.UserAuth   = userAuth;

                return(userAuthResponse);
            }
        }
Пример #20
0
        public IUserAuthDetails CreateOrMergeAuthSession(IAuthSession authSession, IAuthTokens tokens)
        {
            var userAuth = GetUserAuth(authSession, tokens) ?? new JarsUserAuth();

            var authDetails = UserAuthDetailsRepository.Where(u => u.Provider == tokens.Provider && u.UserId == tokens.UserId)
                              .FirstOrDefault();

            if (authDetails == null)
            {
                authDetails = new JarsUserAuthDetails
                {
                    Provider = tokens.Provider,
                    UserId   = tokens.UserId,
                };
            }

            authDetails.PopulateMissing(tokens, overwriteReserved: true);
            userAuth.PopulateMissingExtended(authDetails);

            userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.CreatedDate == default(DateTime))
            {
                userAuth.CreatedDate = userAuth.ModifiedDate;
            }

            userAuth = UserAuthRepository.CreateUpdate(userAuth as JarsUserAuth, MODIEFIED_BY);

            authDetails.UserAuthId = userAuth.Id;

            authDetails.ModifiedDate = userAuth.ModifiedDate;
            if (authDetails.CreatedDate == default(DateTime))
            {
                authDetails.CreatedDate = userAuth.ModifiedDate;
            }

            authDetails = UserAuthDetailsRepository.CreateUpdate(authDetails, MODIEFIED_BY);

            return(authDetails);
        }
Пример #21
0
        public object Any(LogonModels request)
        {
            if (request.GetInfo)
            {
                return(this.GetSession().IsAuthenticated);
            }

            if (request.LogOut)
            {
                FormsAuthentication.SignOut();
            }

            if (request.ResetPassword)
            {
                var userAuth = UserAuthRepository.GetUserAuthByUserName(request.Email);

                if (userAuth == null)
                {
                    request.ResponseResult.ResultStatus = ResultStatuses.Warning;
                    request.ResponseResult.Messages.Add("The specified Email address was not found.");
                    return(request);
                }

                EmailService.SendSmtpEmail(this.BuildEmailMessage(request.Email));

                request.ResponseResult.ResultStatus = ResultStatuses.Success;
                request.ResponseResult.Messages.Add("Please follow the link sent to your Email to reset your password.");
                return(request);
            }

            if (string.IsNullOrEmpty(request.UserName) || string.IsNullOrEmpty(request.Password))
            {
                return(false);
            }

            FormsAuthentication.SetAuthCookie(request.UserName, request.RememberMe);
            return(true);
        }
Пример #22
0
        public void SaveUserAuth(IAuthSession authSession)
        {
            if (authSession == null)
            {
                throw new ArgumentNullException(nameof(authSession));
            }

            var userAuth = !authSession.UserAuthId.IsNullOrEmpty()
                ? UserAuthRepository.GetById(int.Parse(authSession.UserAuthId))
                : authSession.ConvertTo <JarsUserAuth>();

            if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty())
            {
                userAuth.Id = int.Parse(authSession.UserAuthId);
            }

            userAuth.ModifiedDate = DateTime.UtcNow;
            if (userAuth.CreatedDate == default(DateTime))
            {
                userAuth.CreatedDate = userAuth.ModifiedDate;
            }

            UserAuthRepository.CreateUpdate(userAuth, MODIEFIED_BY);
        }
Пример #23
0
        public IUserAuth GetUserAuth(string userAuthId)
        {
            int _userAuthId = int.Parse(userAuthId);

            return(UserAuthRepository.GetById(_userAuthId));
        }
        public ActionResult CheckIfEmailExist(string email)
        {
            var mgr = new UserAuthRepository();

            return(Json(mgr.checkIfEmailExist(email)));
        }
        public ActionResult CheckEmail(string email)
        {
            var mgr = new UserAuthRepository();

            return(Json(mgr.CheckIfEmailExist(email), JsonRequestBehavior.AllowGet));
        }