//[ValidateAntiForgeryToken]
        public async Task <ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePhoneNumberAsync(model.userID, model.PhoneNumber, model.Code);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(model.userID);

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                sendEmail sm           = new sendEmail();
                string    EmailSubject = "FICA requirements for NWWT Silent Auctions";
                string    EMailBody    = $"Thank you {model.CompanyName} for registering for NWWT Silent Auctions.\r\n\r\n Please email a copy of the responsible person’s ID, Company registration certificate (if applicable), proof of address and VAT certificate (if applicable), within 7 days to avoid deregistration, to: [email protected] \r\n \r\n Thank you for your support. \r\n\r\n Kind regards \r\n\r\n \r\n\r\n \r\n\r\n NWWT Silent Auctions Team";
                string    res          = sm.SendEmailFB(model.email, EmailSubject, EMailBody, "*****@*****.**", null);

                return(RedirectToAction("Index", "Home", new { Message = "Cell Phone successfully verified" }));
            }
            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Failed to verify phone");
            return(View(model));
        }
        // GET: SendEmail
        public ActionResult Index()
        {
            sendEmail sm           = new sendEmail();
            string    EmailSubject = "FICA requirements for NWWT Silent Auctions";
            string    EMailBody    = "Thank you for registering for NWWT Silent Auctions.\r\n\r\n Please email a copy of the responsible person’s ID, Company registration certificate (if applicable), proof of address and VAT certificate (if applicable), within 7 days to avoid deregistration, to: [email protected] \r\n \r\n Thank you for your support. \r\n\r\n Kind regards \r\n\r\n \r\n\r\n \r\n\r\n NWWT Silent Auctions Team";
            string    res          = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, "*****@*****.**");

            return(View());
        }
        public async Task <ActionResult> AddPhoneNumber(ResentCodeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.email);

            if (user != null)
            {
                model.userID = user.Id;
            }
            // Generate the token and send it

            //              var code = await UserManager.GenerateChangePhoneNumberTokenAsync(model.userID, model.PhoneNumber);
            bool smsNotifications = true;

            if (smsNotifications)
            {
                var smscode = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, model.PhoneNumber);

                // FB added
                smsMGT smg           = new smsMGT();
                string messagestring = "Your security code for Silent Auction is: " + smscode;
                var    res           = smg.SendSingleSMS("1", model.PhoneNumber, messagestring);
                if (res != "success")
                {
                    string    EmailSubject = "OTP SMS NOT sent successfully";
                    string    EMailBody    = $"OTP SMS NOT sent successfully to customer {user.CompanyName}" + " to change phone " + ".  Error = " + res;
                    sendEmail sm           = new sendEmail();
                    string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                    ViewBag.errorMessage = "Cell Phone number not correct. Log in and provide correct number or contact NWWT at [email protected]";
                    return(View("Error"));
                }
            }

            return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.PhoneNumber, id = user.Id }));
        }
Example #4
0
        // Hier
        public Bid BidLogic(Bid bid)
        {
            currentBuyer.NewBuyerHaveCellNumber = false;
            currentBuyer.OutBuyerHaveCellNumber = false;
            currentBuyer.NewBuyerID             = bid.BuyerId;     // Die nuwe id wat oorkom.

            using (AuctionDBEntities db = new AuctionDBEntities()) // make sure to get the latest info from DB and not the immage of DB.
            {
                tblRoll tblRollAfter = db.tblRolls.Find(bid.ID);   // find the latest info on db.
                if (tblRollAfter.Increments == null)
                {
                    tblRollAfter.Increments = 0;
                }
                if (tblRollAfter.BiddingPrice == null)
                {
                    tblRollAfter.BiddingPrice = 0;
                }
                if (bid.NewBidPrice >= (tblRollAfter.BiddingPrice + tblRollAfter.Increments))
                {
                    double            ExtendBitTime;
                    bool              AuctionSMS         = false;
                    ltRollDescription ltRollDescriptions = db.ltRollDescriptions.Find(bid.RollId);
                    if (ltRollDescriptions != null)
                    {
                        ExtendBitTime = System.Convert.ToDouble(ltRollDescriptions.AuctionDelayTime);
                        AuctionSMS    = ltRollDescriptions.SmsNotification;
                    }
                    else
                    {
                        ExtendBitTime = 5;
                        AuctionSMS    = false;
                    }

                    //

                    bid.BidTotalPrice = bid.NewBidPrice * tblRollAfter.Quantity;
                    if (DateTime.Now <= tblRollAfter.DateTimeClose)
                    {
                        tblRollAfter.DateTimeBid = DateTime.Now;

                        if (DateTime.Now.AddMinutes(ExtendBitTime) >= tblRollAfter.DateTimeClose)
                        {
                            tblRollAfter.DateTimeClose = DateTime.Now.AddMinutes(ExtendBitTime); // add time before close.
                            db.UpdateBidTimeClose(bid.ID, tblRollAfter.DateTimeClose);
                        }
                        // Kan later weer terugsit.
                        //if (currentBuyer.NewBuyerID != tblRollAfter.BuyerId) // Not same outgoing and new bidder.
                        //{
                        // Get outgoing bidder info
                        tblCustomer tblCustomersOut = db.tblCustomers.Find(tblRollAfter.BuyerId);
                        currentBuyer.OutBuyerCell = tblCustomersOut.Phone;
                        if (currentBuyer.OutBuyerCell != null && currentBuyer.OutBuyerCell != "")
                        {
                            currentBuyer.OutBuyerHaveCellNumber = true;
                        }

                        // Get incomming bidder info

                        tblCustomer tblCustomersIn = db.tblCustomers.Find(currentBuyer.NewBuyerID);
                        currentBuyer.NewBuyerCell = tblCustomersIn.Phone;
                        if (currentBuyer.NewBuyerCell != null && currentBuyer.NewBuyerCell != "")
                        {
                            currentBuyer.NewBuyerHaveCellNumber = true;
                        }
                        //                        }

                        // Huidige koper

                        // Laaste voor update.
                        tblRoll tblRollLast = db.tblRolls.Find(bid.ID); // find the latest info on db.
                        if (tblRollLast.Increments == null)
                        {
                            tblRollLast.Increments = 0;
                        }
                        if (tblRollLast.BiddingPrice == null)
                        {
                            tblRollLast.BiddingPrice = 0;
                        }

                        if (bid.NewBidPrice >= (tblRollLast.BiddingPrice + tblRollLast.Increments))
                        {
                            if (tblRollLast.Quantity_Lot == "Lot")
                            {
                                bid.BidTotalPrice = bid.NewBidPrice;
                            }
                            else
                            {
                                bid.BidTotalPrice = bid.NewBidPrice * tblRollAfter.Quantity;
                            }

                            // Kry die Auction Buyer Nommer

                            string AuctionBuyerNumber;

                            BuyerNo buyeNo = db.BuyerNoes.FirstOrDefault(t => t.CustomerID == bid.BuyerId && t.RollID == bid.RollId);
                            if (buyeNo == null)
                            {
                                AuctionBuyerNumber = "INT " + bid.BuyerId.ToString();
                            }
                            else
                            {
                                AuctionBuyerNumber = "B " + buyeNo.BuyerNumber;
                            }

                            db.UpdateBidder(bid.ID, bid.BuyerId, bid.NewBidPrice, bid.BidTotalPrice, tblRollAfter.DateTimeBid, AuctionBuyerNumber);
                            db.AddBidHistory(bid.ID, bid.RollId, tblRollAfter.Lot, tblRollAfter.SellerId, bid.BuyerId, bid.NewBidPrice, bid.BidTotalPrice, tblRollAfter.DateTimeBid, bid.UserID);

                            // Laai defaults

                            DefaultSetupModel dm = LoadDefs(0); // Get the default values vir stuur van sms

                            // Sal net sms stuur as koper cell het, spesifieke auction verys dit en default is aan.

                            // Sms outgoing bidder
                            if (currentBuyer.OutBuyerHaveCellNumber && AuctionSMS && dm.SMSAllFunctionality == true && dm.SMSOutBidder == true)
                            {
                                string x = string.Format("{0:0,000}", bid.NewBidPrice);

                                smsMGT smg           = new smsMGT();
                                string messagestring = $"Silent auction: Your bid for Lot {tblRollAfter.Lot} has been exceeded. Current bid is : R {x}";
                                var    res           = smg.SendSingleSMS("1", currentBuyer.OutBuyerCell, messagestring);
                                if (res != "success")
                                {
                                    string    EmailSubject = "SMS NOT sent successfully";
                                    string    EMailBody    = $"SMS NOT sent successfully to out bidder {tblCustomersOut.CompanyName}" + ".  Error = " + res;
                                    sendEmail sm           = new sendEmail();
                                    string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                                }
                            }

                            // Sms new bidder.
                            if (currentBuyer.NewBuyerHaveCellNumber && AuctionSMS && dm.SMSAllFunctionality == true && dm.SMSNewBidder == true)
                            {
                                string y = string.Format("{0:0,000}", bid.NewBidPrice);

                                smsMGT smg           = new smsMGT();
                                string messagestring = $"Silent auction: Your bid for Lot {tblRollAfter.Lot} has been accepted. Your bid is : R {y}";
                                var    res           = smg.SendSingleSMS("1", currentBuyer.NewBuyerCell, messagestring);

                                if (res != "success")
                                {
                                    string    EmailSubject = "SMS NOT sent successfully";
                                    string    EMailBody    = $"SMS NOT sent successfully to new bidder {tblCustomersIn.CompanyName}" + "  " + res;
                                    sendEmail sm           = new sendEmail();
                                    string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                                }
                            }
                            if (bid.NewBidPrice >= (tblRollAfter.BiddingPrice + (tblRollAfter.Increments * 10)))
                            {
                                // email warning to NWWT
                                sendEmail sm           = new sendEmail();
                                string    y            = string.Format("{0:0,000}", bid.NewBidPrice);
                                string    z            = string.Format("{0:0,000}", tblRollAfter.BiddingPrice);
                                string    EmailSubject = "An extraordinary high bid received";
                                string    EMailBody    = $"An extraordinary high bid was made on Lot {tblRollAfter.Lot} by {tblCustomersIn.CompanyName}. The new bid is : R {y} and the previous bid was R {z}";
                                string    res          = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                            }
                        }
                        else
                        {
                            bid.bidToLow = true;
                        }
                    }
                    else
                    {
                        bid.bidClosed = true;
                    }
                }
                else
                {
                    bid.bidToLow = true;
                }
            }
            return(bid);
        }
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            BidController     loadDefs = new BidController();
            DefaultSetupModel dms      = loadDefs.LoadDefs(0); // Get the default values

            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null)
                {
                    ViewBag.errorMessage = "Email address provided is not registered. Please use correct email address or register as user";
                    return(View("Error"));
                }

                if (dms.emailConfirmationLoginRequired == true)
                {
                    if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                    {
                        // Don't reveal that the user does not exist or is not confirmed
                        // return View("ForgotPasswordConfirmation"); // Moet error gee.
                        ViewBag.errorMessage = "Email address not confirmed";
                        return(View("Error"));
                    }
                }
                if (dms.SMSConfirmationLoginRequired == true)
                {
                    if (user == null || !(await UserManager.IsPhoneNumberConfirmedAsync(user.Id)))
                    {
                        // Don't reveal that the user does not exist or is not confirmed
                        //                        return View("ForgotPasswordConfirmation"); // Moet error gee.
                        ViewBag.errorMessage = "Cell Phone number not confirmed";
                        return(View("Error"));
                    }
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link

                //string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                //var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

                // Fouche
                bool confirmation = false;
                // Stuur confirmation email as nodig
                if (dms.emailConfirmRegistration == true)
                {
                    string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                    //                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");
                    var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                      + "before you can log in.";
                    confirmation = true;
                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                }
                if (dms.SMSAllFunctionality == true && dms.SMSCustRegistration == true)
                {
                    // Generate OTP
                    var smscode = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, user.PhoneNumber);

                    // FB added
                    smsMGT smg           = new smsMGT();
                    string messagestring = "Your security code for Silent Auction is: " + smscode;
                    var    res           = smg.SendSingleSMS("1", user.PhoneNumber, messagestring);
                    if (res != "success")
                    {
                        string    EmailSubject = "OTP SMS NOT sent successfully";
                        string    EMailBody    = $"OTP SMS NOT sent successfully to customer {user.CompanyName}" + " Forgot Password " + ".  Error = " + res;
                        sendEmail sm           = new sendEmail();
                        string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                        ViewBag.errorMessage = "Cell Phone number not correct. Log in and provide correct number or contact NWWT at [email protected]";
                        return(View("Error"));
                    }


                    //
                    confirmation = true;
                    return(RedirectToAction("VerifyPhoneNumberPasswordChange", new { PhoneNumber = user.PhoneNumber, id = user.Id }));
                }
                if (!confirmation)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    //                    return RedirectToAction("Index", "Home");
                    return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
                }
                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            // FB Added
            string aid = "0";
            int?   rollID;

            if (Session["auctionID"] == null)
            {
                rollID = 0;
            }
            else
            {
                aid    = Session["auctionID"].ToString();
                rollID = Int32.Parse(aid);
            }

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(rollID); // Get the default values

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    CompanyName = model.CompanyName, PhoneNumber = model.PhoneNumber, UserName = model.Email, Email = model.Email, CustomerID = model.CustomerID, ContactPerson = model.ContactPerson, ContactCellPhone = model.ContactCellPhone, PIN = model.PIN
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                // User is created in Accounts table

                if (result.Succeeded)
                {
                    UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, model.CompanyName));

                    // FB added this
                    // User is successfully created in Accounts table.
                    // Create Customer record with Basic info al is die inligting nie bevestig deur email of sms
                    //

                    tblCustomer tblCustomers  = new tblCustomer();
                    tblCustomer tblCustomerEx = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);
                    string      companyName;
                    string      Email;

                    if (tblCustomerEx == null)                    // voeg by
                    {
                        tblCustomers.CustomerID    = model.Email; // Kan dalk later verander.
                        tblCustomers.CompanyName   = model.CompanyName;
                        tblCustomers.CompanyID     = model.CustomerID;
                        tblCustomers.eMail         = model.Email;
                        tblCustomers.Phone         = model.PhoneNumber;
                        tblCustomers.ContactPerson = model.ContactPerson;
                        tblCustomers.CellPhone     = model.ContactCellPhone;
                        tblCustomers.Active        = true;
                        tblCustomers.VATRegistered = false;
                        tblCustomers.PIN           = model.PIN;
                        companyName = model.CompanyName;
                        Email       = model.Email;

                        db.tblCustomers.Add(tblCustomers);
                        db.SaveChanges();
                    }
                    else
                    {
                        tblCustomer tblCustomersF = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);
                        db.Entry(tblCustomersF).State = EntityState.Modified;
                        tblCustomersF.CompanyName     = model.CompanyName;
                        tblCustomersF.CompanyID       = model.CustomerID;
                        tblCustomersF.eMail           = model.Email;
                        tblCustomersF.Phone           = model.PhoneNumber;
                        tblCustomersF.ContactPerson   = model.ContactPerson;
                        tblCustomersF.CellPhone       = model.ContactCellPhone;
                        tblCustomersF.Active          = true;
                        tblCustomersF.VATRegistered   = false;
                        tblCustomersF.PIN             = model.PIN;
                        companyName = model.CompanyName;
                        Email       = model.Email;

                        db.SaveChanges();
                    }

                    BidController     loadDefs = new BidController();
                    DefaultSetupModel dms      = loadDefs.LoadDefs(0); // Get the default values
                    bool confirmation          = false;
                    // Stuur confirmation email as nodig
                    if (dms.emailConfirmRegistration == true)
                    {
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                        ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                                          + "before you can log in.";
                        await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        confirmation = true;
                    }
                    if (dms.SMSAllFunctionality == true && dms.SMSCustRegistration == true)
                    {
                        // Generate OTP
                        var smscode = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, model.PhoneNumber);

                        // FB added
                        smsMGT smg           = new smsMGT();
                        string messagestring = "Your security code for Silent Auction is: " + smscode;
                        var    res           = smg.SendSingleSMS("1", model.PhoneNumber, messagestring);

                        if (res != "success")
                        {
                            string    EmailSubject = "OTP SMS NOT sent successfully";
                            string    EMailBody    = $"OTP SMS NOT sent successfully to new customer {model.CompanyName}" + ".  Error = " + res + " Number " + model.PhoneNumber;
                            sendEmail sm           = new sendEmail();
                            string    emalres      = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);
                            ViewBag.errorMessage = "Cell Phone number not correct. Log in and provide correct number or contact NWWT at [email protected]";
                            return(View("Error"));
                            /// FB
                        }
                        confirmation = true;
                        return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.PhoneNumber, id = user.Id, email = Email, compName = companyName }));
                    }
                    if (!confirmation)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // FB Added
            string aid = "0";
            int?   rollID;

            if (Session["auctionID"] == null)
            {
                rollID = 0;
            }
            else
            {
                aid    = Session["auctionID"].ToString();
                rollID = Int32.Parse(aid);
            }


            // Find user record for role id.

            BidController     bd = new BidController();
            DefaultSetupModel dm = bd.LoadDefs(rollID); // Get the default values

            ViewBag.BackgroundColor     = dm.BackgroundColor;
            ViewBag.TexColor            = dm.FontColor;
            ViewBag.LogoBackgroundColor = dm.LogoBackgroundColor;
            ViewBag.LogoPath            = dm.LogoPath;
            ViewBag.LogoName            = dm.LogoName;

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.Id) && dm.emailConfirmationLoginRequired == true)
                {
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend");

                    ViewBag.errorMessage = "You must have confirmed your email to log on.";
                    return(View("Error"));
                }

                if (!await UserManager.IsPhoneNumberConfirmedAsync(user.Id) && dm.SMSConfirmationLoginRequired == true)
                {
                    // Stuur weer boodskap.

                    ViewBag.errorMessage = "You must confirmed your details before login. Re-send Code";
                    ViewBag.email        = model.Email;
                    return(View("ResentCode"));
                }
                // Fouche : Adde Active check
                tblCustomer tblCustomerEx = db.tblCustomers.FirstOrDefault(i => i.CustomerID == model.Email);

                if (tblCustomerEx != null)     // Customer bestaan
                {
                    if (!tblCustomerEx.Active) // Customer nie aangelog nie.
                    {
                        ViewBag.errorMessage = "Log in not authorised. Please contact NWWT at [email protected]";

                        // Stuur email vir NWWT
                        // email warning to NWWT
                        sendEmail sm           = new sendEmail();
                        string    EmailSubject = "An attempt to log in was made by a suspended customer";
                        string    EMailBody    = $"An attempt to log in was made by a suspended customer. Customer {tblCustomerEx.CompanyName}.";
                        string    res          = sm.SendEmailFB("*****@*****.**", EmailSubject, EMailBody, null, null);


                        return(View("Error"));
                    }
                }
            }


            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }