Пример #1
0
        public ActionResult Users()
        {
            if (Session["UserInfo"] != null)
            {
                List <UserViewModel> lstUserModel = new List <UserViewModel>();

                using (var context = new GameNepalEntities())
                {
                    var users = context.Users.Where(x => x.type != (int)UserTypes.Admin).ToList();
                    foreach (var user in users)
                    {
                        UserViewModel userModel = new UserViewModel
                        {
                            Id         = user.id,
                            FirstName  = user.firstname,
                            LastName   = user.lastname,
                            Email      = user.email,
                            Phone      = user.phone,
                            Gender     = user.gender,
                            City       = user.city,
                            CreateDate = user.createdate,
                            UpdateDate = user.updatedate,
                            IsActive   = user.isActive,
                            AgeGroup   = user.agegroup
                        };
                        lstUserModel.Add(userModel);
                    }
                }

                return(View(lstUserModel));
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #2
0
        public ActionResult MyProfile()
        {
            if (Session["UserInfo"] != null)
            {
                var sessionUser = Session["UserInfo"] as User;
                using (var context = new GameNepalEntities())
                {
                    var user = context.Users
                               .Where(x => x.id.Equals(sessionUser.id) && x.isActive)
                               .FirstOrDefault();

                    if (user != null)
                    {
                        var userModel = new UserViewModel
                        {
                            Id        = user.id,
                            FirstName = user.firstname,
                            LastName  = user.lastname,
                            Email     = user.email,
                            Phone     = user.phone,
                            Gender    = user.gender,
                            City      = user.city,
                            AgeGroup  = user.agegroup
                        };

                        return(View("MyProfile", userModel));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #3
0
        public ActionResult CancelTransaction(int id)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;
                using (var context = new GameNepalEntities())
                {
                    var transaction = context.Transactions
                                      .Where(x => x.id.Equals(id) && x.status.Equals((int)TransactionStatus.New) && x.userid.Equals(user.id))
                                      .FirstOrDefault();

                    if (transaction != null)
                    {
                        transaction.status     = (int)TransactionStatus.Cancelled;
                        transaction.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["CancelErrorMsg"]   = null;
                        TempData["CancelSuccessMsg"] = "<strong>Your order is cancelled successfully.</strong>";
                        return(RedirectToAction("TransactionHistory"));
                    }

                    TempData["CancelErrorMsg"] = "<strong>Some error occured cancelling this order. Please try again.</strong>";
                    return(View("TransactionHistory"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #4
0
        public ActionResult PaymentPartners()
        {
            if (Session["UserInfo"] != null)
            {
                List <PaymentPartnerViewModel> lstPaymentPartnerVM = new List <PaymentPartnerViewModel>();

                using (var context = new GameNepalEntities())
                {
                    var paymentPartners = context.PaymentPartners.ToList();
                    foreach (var paymentPartner in paymentPartners)
                    {
                        PaymentPartnerViewModel model = new PaymentPartnerViewModel
                        {
                            Id          = paymentPartner.id,
                            PartnerName = paymentPartner.partnername,
                            PaymentInfo = paymentPartner.paymentinfo,
                            CreateDate  = paymentPartner.createdate.Value,
                            UpdateDate  = paymentPartner.updatedate.Value,
                            IsActive    = paymentPartner.isActive,
                        };
                        lstPaymentPartnerVM.Add(model);
                    }
                }

                return(View(lstPaymentPartnerVM));
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #5
0
        public ActionResult ValidateToken(string uid, string token)
        {
            var validDate = GetValidPassowrdResetDateTime();

            using (var context = new GameNepalEntities())
            {
                var tokenMatchingUser = (from t in context.PasswordTokens
                                         join u in context.Users on t.userid equals u.id
                                         let tokenStr = t.token.ToString()
                                                        where (tokenStr == token) && t.isValid &&
                                                        t.createdate >= validDate && u.isActive
                                                        select u).FirstOrDefault();

                if (tokenMatchingUser != null)
                {
                    var hashedUserEmail = Helper.EncodeToBase64(tokenMatchingUser.email);

                    if (hashedUserEmail == uid)
                    {
                        Session["UserInfo"] = tokenMatchingUser;
                        return(RedirectToAction("ResetPassword"));
                    }
                }

                ViewBag.ErrorMsg = "Sorry, the link you have entered is not valid or has been expired.";
                return(View("Error"));
            }
        }
Пример #6
0
        public ActionResult EditProfile(UserViewModel userModel)
        {
            ModelState.Remove("Password");
            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var user = Session["UserInfo"] as User;
                        if (user != null)
                        {
                            var emailExists = context.Users
                                              .Where(x => x.email.Equals(userModel.Email) && !x.id.Equals(user.id))
                                              .FirstOrDefault();

                            if (emailExists != null)
                            {
                                TempData["ErrorMsg"] = "The email address you entered already exists in our system. <br/>Please use a different email address or try Forgot Password from the login page.";
                                return(PartialView("_EditProfile", userModel));
                            }

                            user.type = (int)UserTypes.General;

                            user.updatedate = Helper.GetCurrentDateTime();
                            user.isActive   = true;

                            user.firstname = userModel.FirstName;
                            user.lastname  = userModel.LastName;
                            user.email     = userModel.Email;
                            user.phone     = userModel.Phone;

                            user.gender   = userModel.Gender;
                            user.city     = userModel.City;
                            user.agegroup = userModel.AgeGroup;

                            context.Users.Add(user);
                            context.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            context.SaveChanges();

                            Session["UserInfo"] = user;
                        }
                        TempData["ErrorMsg"] = null;
                        return(Json(new { success = true }));
                    }
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(PartialView("_EditProfile", userModel));
                }
            }
            else
            {
                return(PartialView("_EditProfile", userModel));
            }
        }
Пример #7
0
        public ActionResult CreateTransaction(TransactionModel transactionModel)
        {
            var user = Session["UserInfo"] as User;

            ViewBag.UserName = user.firstname;

            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var matchingPaymentId = context.Transactions
                                                .Where(x => x.paymentid.Equals(transactionModel.PaymentId) &&
                                                       !x.status.Equals((int)TransactionStatus.Cancelled))
                                                .FirstOrDefault();

                        if (matchingPaymentId != null)
                        {
                            TempData["ErrorMsg"] = "The payment confirmation number already exists in our system.";
                            return(View("Index", transactionModel));
                        }

                        var transaction = new Transaction
                        {
                            createdate = Helper.GetCurrentDateTime(),
                            updatedate = Helper.GetCurrentDateTime(),
                            status     = (int)TransactionStatus.New,
                            userid     = user.id,

                            paypartnerid = transactionModel.PaymentPartnerId,
                            paymentid    = transactionModel.PaymentId,
                            username     = transactionModel.Username,
                            gameid       = transactionModel.GameId,
                            amount       = transactionModel.Amount,
                            remarks      = transactionModel.Remarks
                        };

                        context.Transactions.Add(transaction);
                        context.Entry(transaction).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();
                    }
                    TempData["ErrorMsg"]   = null;
                    TempData["SuccessMsg"] = "Your last order is placed successfully. Please <a href='/User/TransactionHistory'> check transaction history.</a>";
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(View("Index", transactionModel));
                }
            }
            else
            {
                return(View("Index", transactionModel));
            }
        }
Пример #8
0
        public ActionResult EditTransaction(TransactionModel transactionModel)
        {
            var user = Session["UserInfo"] as User;

            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var transaction = context.Transactions
                                          .Where(x => x.id.Equals(transactionModel.Id) && x.userid.Equals(user.id))
                                          .FirstOrDefault();

                        var matchingPaymentId = context.Transactions
                                                .Where(x => x.paymentid.Equals(transactionModel.PaymentId) &&
                                                       !x.status.Equals((int)TransactionStatus.Cancelled) &&
                                                       !x.id.Equals(transactionModel.Id))
                                                .FirstOrDefault();

                        if (matchingPaymentId != null)
                        {
                            TempData["ErrorMsg"] = "This payment confirmation number already exists in our system.";
                            return(PartialView("_EditTransaction", transactionModel));
                        }

                        transaction.updatedate = Helper.GetCurrentDateTime();
                        transaction.status     = (int)TransactionStatus.New;
                        transaction.userid     = user.id;

                        transaction.paypartnerid = transactionModel.PaymentPartnerId;
                        transaction.paymentid    = transactionModel.PaymentId;
                        transaction.username     = transactionModel.Username;
                        transaction.gameid       = transactionModel.GameId;
                        transaction.amount       = transactionModel.Amount;
                        transaction.remarks      = transactionModel.Remarks;

                        context.Transactions.Add(transaction);
                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;

                        context.SaveChanges();
                    }
                    TempData["ErrorMsg"] = null;
                    return(Json(new { success = true }));
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(PartialView("_EditTransaction", transactionModel));
                }
            }
            else
            {
                return(PartialView("_EditTransaction", transactionModel));
            }
        }
Пример #9
0
        public ActionResult TransactionHistory()
        {
            if (Session["UserInfo"] != null)
            {
                var user                 = Session["UserInfo"] as User;
                var transactionList      = new List <Transaction>();
                var transactionModelList = new List <TransactionModel>();
                var gameList             = new TransactionModel().GamesList;
                var paymentPartners      = new TransactionModel().PaymentPartners;

                using (var context = new GameNepalEntities())
                {
                    transactionList = context.Transactions
                                      .Where(x => x.userid.Equals(user.id))
                                      .ToList();

                    foreach (var transaction in transactionList)
                    {
                        var transactionModel = new TransactionModel
                        {
                            Id         = transaction.id,
                            UpdateDate = transaction.updatedate,
                            PaymentId  = transaction.paymentid,
                            Amount     = transaction.amount,
                            Status     = transaction.status,
                            Username   = transaction.username,
                            Remarks    = transaction.remarks
                        };

                        transactionModel.CurrentStatus = Helper.GetCurrentTransactionStatus(transaction.status);

                        transactionModel.Game = gameList
                                                .Where(x => x.Value.Equals(transaction.gameid.ToString()))
                                                .Select(x => x.Text).FirstOrDefault();

                        transactionModel.PaymentParnter = paymentPartners
                                                          .Where(x => x.Value.Equals(transaction.paypartnerid.ToString()))
                                                          .Select(x => x.Text).FirstOrDefault();

                        if (string.IsNullOrEmpty(transactionModel.PaymentParnter))
                        {
                            transactionModel.PaymentParnter = "N/A";
                        }

                        transactionModelList.Add(transactionModel);
                    }
                }
                return(View(transactionModelList));
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #10
0
        public ActionResult Login(UserViewModel userModel)
        {
            ModelState.Remove("FirstName");
            ModelState.Remove("LastName");
            ModelState.Remove("Email");
            ModelState.Remove("Phone");
            ModelState.Remove("Password");

            var email = Request.Form["txtUsername"].ToString();
            var pwd   = Request.Form["txtPassword"].ToString();

            TempData["ErrorMsg"] = null;
            var hashedPwd = Helper.EncodeToBase64(pwd);

            try
            {
                using (var context = new GameNepalEntities())
                {
                    var user = context.Users.Where(x => x.isActive &&
                                                   x.email.Equals(email) &&
                                                   x.password.Equals(hashedPwd)).FirstOrDefault();

                    if (user != null)
                    {
                        Session["UserInfo"] = user;

                        if (user.type == (int)UserTypes.Admin)
                        {
                            return(RedirectToAction("Index", "Admin"));
                        }

                        return(RedirectToAction("Index", "User"));
                    }

                    else
                    {
                        TempData["ErrorMsg"] = "<strong>Invalid credentails. Username and/or password does not match. </strong>";
                        return(View("Login"));
                    }
                }
            }
            catch (Exception e)
            {
                TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                return(View("Login"));
            }
        }
Пример #11
0
        public ActionResult AddPaymentPartner(PaymentPartnerViewModel model)
        {
            if (Session["UserInfo"] != null)
            {
                TempData["ErrorMsg"] = "";
                if (ModelState.IsValid)
                {
                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var existingAccount = context.PaymentPartners
                                                  .Where(x => x.partnername.Equals(model.PartnerName))
                                                  .FirstOrDefault();

                            if (existingAccount != null)
                            {
                                TempData["ErrorMsg"] = "<strong>This account name already exists in the system.</strong>";
                                return(PartialView("_AddPaymentPartner", model));
                            }

                            var payModel = new PaymentPartner
                            {
                                partnername = model.PartnerName,
                                paymentinfo = model.PaymentInfo,
                                isActive    = true,
                                createdate  = Helper.GetCurrentDateTime(),
                                updatedate  = Helper.GetCurrentDateTime()
                            };

                            context.Entry(payModel).State = System.Data.Entity.EntityState.Added;
                            context.SaveChanges();
                        }
                        TempData["ErrorMsg"] = null;
                        return(Json(new { success = true }));
                    }
                    catch (Exception e)
                    {
                        TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                        return(PartialView("_AddPaymentPartner", model));
                    }
                }
                return(PartialView("_AddPaymentPartner", model));
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #12
0
        public ActionResult ProcessTransaction(int id, string userAction)
        {
            if (Session["UserInfo"] != null)
            {
                using (var context = new GameNepalEntities())
                {
                    var transaction = context.Transactions
                                      .Where(x => x.id.Equals(id))
                                      .FirstOrDefault();

                    if (transaction != null)
                    {
                        if (userAction == "Cancel" && transaction.status == (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.Cancelled;
                        }
                        else if (userAction == "Approve" && transaction.status == (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.Processed;
                        }
                        else if (userAction == "Reset" && transaction.status != (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.New;
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }

                        transaction.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["CancelErrorMsg"]   = null;
                        TempData["CancelSuccessMsg"] = "<strong>Order is updated successfully.</strong>";
                        return(RedirectToAction("Index"));
                    }

                    TempData["CancelErrorMsg"] = "<strong>Some error occured performing this operation. Please try again.</strong>";
                    return(RedirectToAction("Index"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #13
0
        public ActionResult UpdatePaymentPartner(int id, string status)
        {
            if (Session["UserInfo"] != null)
            {
                using (var context = new GameNepalEntities())
                {
                    var paymentPartner = context.PaymentPartners
                                         .Where(x => x.id.Equals(id))
                                         .FirstOrDefault();

                    if (paymentPartner != null)
                    {
                        if (status == "Deactivate" && paymentPartner.isActive)
                        {
                            paymentPartner.isActive = false;
                        }

                        else if (status == "Activate" && !paymentPartner.isActive)
                        {
                            paymentPartner.isActive = true;
                        }

                        else
                        {
                            return(RedirectToAction("PaymentPartners"));
                        }

                        paymentPartner.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(paymentPartner).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["UpdateUserErrorMsg"]   = null;
                        TempData["UpdateUserSuccessMsg"] = "<strong>Payment info is updated successfully.</strong>";
                        return(RedirectToAction("PaymentPartners"));
                    }

                    TempData["UpdateUserErrorMsg"] = "<strong>Some error occured performing this operation. Please try again.</strong>";
                    return(RedirectToAction("PaymentPartners"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #14
0
        public ActionResult ForgotPassword(FormCollection formCollection)
        {
            TempData["SuccessMsg"] = "<strong> Please check your email to reset your password.</strong>";
            var email = formCollection.Get("txtUsername").ToString();

            try
            {
                using (var context = new GameNepalEntities())
                {
                    var user = context.Users.Where(x => x.isActive &&
                                                   x.email.Equals(email)).FirstOrDefault();

                    if (user != null)
                    {
                        var token           = GenerateToken(user.id);
                        var hashedUserEmail = Helper.EncodeToBase64(user.email);

                        var urlBuilder =
                            new System.UriBuilder(Request.Url.AbsoluteUri)
                        {
                            Path  = Url.Action("ValidateToken", "Home"),
                            Query = "uid=" + hashedUserEmail + "&token=" + token,
                        };

                        Uri    uri     = urlBuilder.Uri;
                        string url     = urlBuilder.ToString();
                        var    message = "Dear " + user.firstname + ", <br/> To securely reset your password, please click the link below:<br/>"
                                         + "<a target='_blank' href= '" + url + "'>  Click Here </a>" + "<br/> <br/> Or you can copy paste this text in a new tab. <br/> "
                                         + url + "<br/> <br/> <b> This link is only valid for 30 minutes from the time it is first generated.</b> If you do not reset your password "
                                         + "during this time, you will need to submit another password reset request.";

                        Helper.Email(user.email, message);
                    }
                }
            }
            catch (Exception e)
            {
                TempData["SuccessMsg"]        = null;
                TempData["ForgotPwdErrorMsg"] = "<strong> Some error occurred processing your request.</strong>";
            }

            return(View());
        }
Пример #15
0
        public string GenerateToken(int userId)
        {
            try
            {
                using (var context = new GameNepalEntities())
                {
                    var validDate = GetValidPassowrdResetDateTime();

                    var existingToken = context.PasswordTokens
                                        .Where(x => x.userid.Equals(userId) && x.isValid && x.createdate >= validDate)
                                        .FirstOrDefault();

                    if (existingToken == null)
                    {
                        var token    = Guid.NewGuid();
                        var pwdToken = new PasswordToken();

                        pwdToken.createdate = Helper.GetCurrentDateTime();
                        pwdToken.token      = token;
                        pwdToken.userid     = userId;
                        pwdToken.isValid    = true;

                        context.PasswordTokens.Add(pwdToken);
                        context.Entry(pwdToken).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();
                        return(token.ToString());
                    }
                    else
                    {
                        return(existingToken.token.ToString());
                    }
                }
            }

            catch (Exception e)
            {
                return("");
            }
        }
Пример #16
0
        public ActionResult EditPaymentPartner(int id)
        {
            if (Session["UserInfo"] != null)
            {
                using (var context = new GameNepalEntities())
                {
                    var paymentPartner = context.PaymentPartners
                                         .Where(x => x.id.Equals(id) && x.isActive)
                                         .FirstOrDefault();

                    if (paymentPartner != null)
                    {
                        PaymentPartnerViewModel model = new PaymentPartnerViewModel
                        {
                            Id          = paymentPartner.id,
                            PartnerName = paymentPartner.partnername,
                            PaymentInfo = paymentPartner.paymentinfo
                        };
                        return(PartialView("_EditPaymentPartner", model));
                    }
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #17
0
        public ActionResult EditTransaction(int id)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;
                ViewBag.UserName = user.firstname;

                using (var context = new GameNepalEntities())
                {
                    var transaction = context.Transactions
                                      .Where(x => x.id.Equals(id) && x.status.Equals((int)TransactionStatus.New) && x.userid.Equals(user.id))
                                      .FirstOrDefault();

                    if (transaction != null)
                    {
                        var transactionModel = new TransactionModel
                        {
                            Id = transaction.id,
                            PaymentPartnerId = transaction.paypartnerid,
                            PaymentId        = transaction.paymentid,
                            Amount           = transaction.amount,
                            Status           = transaction.status,
                            Username         = transaction.username,
                            Remarks          = transaction.remarks
                        };

                        return(PartialView("_EditTransaction", transactionModel));
                    }
                    else
                    {
                        return(RedirectToAction("TransactionHistory"));
                    }
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #18
0
        public ActionResult Index()
        {
            if (Session["UserInfo"] != null)
            {
                var user                 = Session["UserInfo"] as User;
                var transactionList      = new List <Transaction>();
                var transactionModelList = new List <UserTransactionViewModel>();
                var gameList             = new TransactionModel().GamesList;
                var partnerList          = new TransactionModel().PaymentPartners;

                using (var context = new GameNepalEntities())
                {
                    var userTransactions = (from trans in context.Transactions
                                            join usr in context.Users on trans.userid equals usr.id
                                            select new
                    {
                        usr.firstname,
                        usr.lastname,
                        usr.email,
                        usr.phone,
                        trans.id,
                        trans.updatedate,
                        trans.paypartnerid,
                        trans.paymentid,
                        trans.amount,
                        trans.status,
                        trans.username,
                        trans.gameid,
                        trans.remarks
                    }).OrderByDescending(x => x.updatedate)
                                           .ToList();

                    foreach (var transaction in userTransactions)
                    {
                        var transactionModel = new UserTransactionViewModel
                        {
                            TransactionId             = transaction.id,
                            LastTransactionUpdateDate = transaction.updatedate,
                            FirstName = transaction.firstname,
                            LastName  = transaction.lastname,
                            Email     = transaction.email,
                            Phone     = transaction.phone,
                            PaymentId = transaction.paymentid,
                            Amount    = transaction.amount,
                            Status    = transaction.status,
                            Username  = transaction.username,
                            Remarks   = transaction.remarks
                        };


                        transactionModel.CurrentStatus = Helper.GetCurrentTransactionStatus(transaction.status);
                        transactionModel.Game          = gameList
                                                         .Where(x => x.Value.Equals(transaction.gameid.ToString()))
                                                         .Select(x => x.Text).FirstOrDefault();

                        transactionModel.PaymentPartner = partnerList
                                                          .Where(x => x.Value.Equals(transaction.paypartnerid.ToString()))
                                                          .Select(x => x.Text).FirstOrDefault();

                        if (string.IsNullOrEmpty(transactionModel.PaymentPartner))
                        {
                            transactionModel.PaymentPartner = "N/A";
                        }

                        transactionModelList.Add(transactionModel);
                    }
                }

                ViewBag.UserName = user.firstname;
                return(View(transactionModelList));
            }
            return(RedirectToAction("Login", "Home"));
        }
Пример #19
0
        public ActionResult Register(UserViewModel userModel)
        {
            var reEnteredPwd = Request.Form["pwdReEntered"].ToString();

            TempData["ErrorMsg"] = "<strong>One or more error occured. </strong>";
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(reEnteredPwd) || userModel.Password != reEnteredPwd)
                {
                    TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                    return(View("Register", userModel));
                }

                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var user = new User();

                        var emailExists = context.Users
                                          .Where(x => x.email.Equals(userModel.Email))
                                          .FirstOrDefault();

                        if (emailExists != null)
                        {
                            TempData["ErrorMsg"] = "<strong>The email address you entered already exists in our system. <br/>Please use a different email address or try forgot Passowrd from the login page</strong>";
                            return(View("Register", userModel));
                        }

                        user.type       = (int)UserTypes.General;
                        user.createdate = Helper.GetCurrentDateTime();
                        user.updatedate = Helper.GetCurrentDateTime();
                        user.isActive   = true;

                        user.firstname = userModel.FirstName;
                        user.lastname  = userModel.LastName;
                        user.email     = userModel.Email;
                        user.phone     = userModel.Phone;

                        user.gender   = userModel.Gender;
                        user.city     = userModel.City;
                        user.password = Helper.EncodeToBase64(userModel.Password);
                        user.agegroup = userModel.AgeGroup;

                        context.Users.Add(user);
                        context.Entry(user).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();

                        Session["UserInfo"] = user;
                    }
                    TempData["ErrorMsg"] = null;
                    return(RedirectToAction("Index", "User"));
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(View("Register", userModel));
                }
            }
            else
            {
                return(View("Register", userModel));
            }
        }
Пример #20
0
        public ActionResult ChangePassword(PasswordModel model)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;
                ViewBag.UserName = user.firstname;

                var oldPassword     = Request.Form["oldPassword"].ToString();
                var reEnteredNewPwd = Request.Form["pwdReEntered"].ToString();

                TempData["ErrorMsg"] = "";
                ViewBag.Success      = false;

                if (ModelState.IsValid)
                {
                    if (model.NewPassword != reEnteredNewPwd)
                    {
                        TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                        return(PartialView("_ChangePassword", model));
                    }

                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var hashedOldPwd = Helper.EncodeToBase64(oldPassword);
                            var hashedNewPwd = Helper.EncodeToBase64(model.NewPassword);

                            var contextUser = context.Users.Where(x => x.id.Equals(user.id) &&
                                                                  x.password.Equals(hashedOldPwd) && x.isActive)
                                              .FirstOrDefault();

                            if (contextUser == null)
                            {
                                TempData["ErrorMsg"] = "<strong>Old password does not match. </strong>";
                                return(PartialView("_ChangePassword", model));
                            }

                            else if (contextUser.password.Equals(hashedNewPwd))
                            {
                                TempData["ErrorMsg"] = "<strong>New password should be different from old password. </strong>";
                                return(PartialView("_ChangePassword", model));
                            }

                            else
                            {
                                contextUser.password   = hashedNewPwd;
                                contextUser.updatedate = Helper.GetCurrentDateTime();

                                context.Users.Add(contextUser);
                                context.Entry(contextUser).State = System.Data.Entity.EntityState.Modified;

                                context.SaveChanges();

                                Session["UserInfo"] = contextUser;
                            }
                        }
                        TempData["ErrorMsg"]   = null;
                        TempData["SuccessMsg"] = "Password changed successfully";
                        ViewBag.Success        = true;
                        return(PartialView("_ChangePassword", model));
                    }

                    catch
                    {
                        TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                        return(PartialView("_ChangePassword", model));
                    }
                }
                else
                {
                    return(PartialView("_ChangePassword", model));
                }
            }
            return(RedirectToAction("Login"));
        }
Пример #21
0
        public ActionResult ResetPassword(PasswordModel model)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;

                var reEnteredNewPwd = Request.Form["pwdReEntered"].ToString();

                TempData["ErrorMsg"] = "";
                if (ModelState.IsValid)
                {
                    if (model.NewPassword != reEnteredNewPwd)
                    {
                        TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                        return(View(model));
                    }

                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var hashedNewPwd = Helper.EncodeToBase64(model.NewPassword);

                            var contextUser = context.Users.Where(x => x.id.Equals(user.id) && x.isActive).FirstOrDefault();

                            if (contextUser.password.Equals(hashedNewPwd))
                            {
                                TempData["ErrorMsg"] = "<strong>New password should be different from old password. </strong>";
                                return(RedirectToAction("ResetPassword"));
                            }

                            else
                            {
                                contextUser.password   = hashedNewPwd;
                                contextUser.updatedate = Helper.GetCurrentDateTime();

                                context.Users.Add(contextUser);
                                context.Entry(contextUser).State = System.Data.Entity.EntityState.Modified;

                                var pwdToken = context.PasswordTokens
                                               .Where(x => x.userid.Equals(contextUser.id)).OrderByDescending(x => x.createdate)
                                               .FirstOrDefault();
                                pwdToken.isValid    = false;
                                pwdToken.updatedate = Helper.GetCurrentDateTime();

                                context.PasswordTokens.Add(pwdToken);
                                context.Entry(pwdToken).State = System.Data.Entity.EntityState.Modified;

                                context.SaveChanges();
                                Session["UserInfo"] = contextUser;
                            }
                        }
                        TempData["ErrorMsg"]   = null;
                        TempData["SuccessMsg"] = "Password changed successfully. Please login again!!";
                        return(RedirectToAction("Login"));
                    }

                    catch
                    {
                        TempData["ErrorMsg"] = "Some unexpected error occured. Please try again!! ";
                        return(RedirectToAction("ResetPassword"));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            return(RedirectToAction("Login"));
        }