public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var identityUser = new ApplicationUser
                {
                    UserName = model.Username,
                    Email    = model.Username
                };

                var identityResults = await _userManager.CreateAsync(identityUser, model.Password);

                if (identityResults.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser);

                    var callbackUrl = Url.Action("ConfirmEmail", "Main", new { userId = identityUser.Id, code = code }, protocol: HttpContext.Request.Scheme);

                    await _emailSend.SendEmailAsync(model.Username, "Confirm Account", $"Please confirm your account by clicking this link:<a href='{callbackUrl}'>Link</a>");

                    await _signInManager.SignInAsync(identityUser, isPersistent : false);

                    return(View(model));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Error in Creating my User. Password requires upper case letter, a non alpha numeric character and a digit.");
                    return(View(model));
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Register(RegistreView model)
        {
            if (ModelState.IsValid)
            {
                var identityUser = new ApplicationUser
                {
                    UserName = model.UserName,
                    Email    = model.UserName
                };
                var identityResults = await userManager.CreateAsync(identityUser, model.Password);

                if (identityResults.Succeeded)
                {
                    var code = await userManager.GenerateEmailConfirmationTokenAsync(identityUser);

                    var callbackUrl = Url.Action("ConfirmEmail", "Main", new { userId = identityUser.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await emailSend.SendEmailAsync(model.UserName, "Confirm Acount",
                                                   $"please Confirm Your Acount By"
                                                   + $"Clicking this link:<a href='{callbackUrl}'>Link</a>");

                    await signInManager.SignInAsync(identityUser, isPersistent : false);

                    return(View(model));
                    //return RedirectToAction("Index", "LoggedIn");
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Error in Creating the User");
                    return(View(model));
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Index(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                var confirmed = await _userManager.IsEmailConfirmedAsync(user);

                if (user == null || !confirmed)
                {
                    return(RedirectToAction("Index", "Main"));
                }
                // Send Email Confirmation

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                var callbackUrl = Url.Action("Index", "ResetPassword", new { userId = user.Id, code = code },
                                             protocol: HttpContext.Request.Scheme);
                await
                _emailSend.SendEmailAsync(model.Email, "Reset Password",
                                          $"Please Reset you Password by " +
                                          $"clicking this link:<a href='{callbackUrl}'>Link</a>");
            }

            return(View(model));
        }
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid) // if user has filled out correct info to register from home/register
            {
                // create new user
                var identityUser = new ApplicationUser {
                    UserName = model.Username,
                    Email    = model.Username // for now set username and email to be email address
                };

                var identityResults = await _userManager.CreateAsync(identityUser, model.Password);

                if (identityResults.Succeeded)
                {
                    // auto generate email confirmation to send to user
                    // create token
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser);

                    // create a url to be sent in email for user to click and confirm account
                    var callbackUrl = Url.Action("ConfirmEmail", "Home", new { userid = identityUser.Id, Code = code },
                                                 protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(model.Username
                                                    , "Confirm Account"
                                                    , $"Confirm your account by " +
                                                    $"clicking this Link:' {callbackUrl} ' "
                                                    );

                    // log user in
                    await _signInManager.SignInAsync(identityUser, isPersistent : false); // isPersistent:false = cookies NOT persistent after browser close

                    // redirect to login page
                    return(View(model));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Error in creating user.");
                    return(View(model));
                }
            }

            return(View());
        }
Beispiel #5
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Set new user object
                var identityUser = new ApplicationUser
                {
                    UserName = model.Username,
                    Email    = model.Username,
                };

                // Create the user with usermanager
                var identityResults = await _userManager.CreateAsync(identityUser, model.Password);

                if (identityResults.Succeeded)
                {
                    // Code is the email confirmation token
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser);

                    // Set the url / method to call when user hits the link
                    var callbackUrl = Url.Action("ConfirmEmail", "Main", new { userId = identityUser.Id, code = code },
                                                 protocol: HttpContext.Request.Scheme);
                    // Send email to user with the confirmation link
                    await _emailSend.SendEmailAsync(model.Username, "Confirm password", "Please confirm your password by" +
                                                    $"clicking this link: {callbackUrl}");

                    // Sign user in
                    await _signInManager.SignInAsync(identityUser, isPersistent : false);

                    return(RedirectToAction("Index", "LoggedIn"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Error while creating user");
                    return(View(model));
                }
            }
            return(View(nameof(Index)));
        }
Beispiel #6
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            model.Membership = MembershipType.PAYG;


            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                var identityUser = new ApplicationUser
                {
                    UserName       = model.EmailAddress,
                    Email          = model.EmailAddress,
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    PhoneNumber    = model.PhoneNumber,
                    Address        = model.Address,
                    Membership     = model.Membership,
                    MyBalance      = 0,
                    DateRegistered = DateTime.Now,
                    CustomerName   = model.FirstName + " " + model.LastName,
                };

                var identityResults = await _userManager.CreateAsync(identityUser, model.Password);

                if (identityResults.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(identityUser);

                    var callbackUrl = Url.Action("ConfirmEmail", "Home", new { userId = identityUser.Id, code = code },
                                                 protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(model.EmailAddress, "Confirm Account",
                                                    $"Welcome " + model.FirstName +
                                                    $" <br />" +
                                                    $" Thanks for Registering on Technicians.ng" +
                                                    $" <br />" +
                                                    $"Please Confirm your account by " +
                                                    $"clicking the button below" +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <a style=\" text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{callbackUrl}'>Confirm my account</a>" +
                                                    $" <br />" +
                                                    $" " +
                                                    $" <br />"
                                                    );


                    await _userManager.AddToRoleAsync(identityUser, "User");

                    await _signInManager.SignInAsync(identityUser, isPersistent : false);

                    return(View("EmailConfirmation"));
                }

                foreach (var error in identityResults.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Error in creating user");
                return(View(model));
            }

            return(View(model));
        }
Beispiel #7
0
        public async Task <IActionResult> Edit(int id, AdminEditViewModel model, ProfileEditViewModel myprofile, CompletedEditViewModel admin)
        {
            var FullName      = _context.Request.FindAsync(id).Result.CustomerName;
            var phone         = _context.Request.FindAsync(id).Result.PhoneNumber;
            var address       = _context.Request.FindAsync(id).Result.Address;
            var membership    = _context.Request.FindAsync(id).Result.MembershipType;
            var requestStatus = _context.Request.FindAsync(id).Result.RequestStatus;
            var adminEmail    = "*****@*****.**";



            var Userid   = _context.Request.FindAsync(id).Result.ApplicationUserId;
            var prevBal  = _context.Users.FindAsync(Userid).Result.MyBalance;
            var date     = _context.Users.FindAsync(Userid).Result.DateRegistered;
            var email    = _context.Users.FindAsync(Userid).Result.Email;
            var fName    = _context.Users.FindAsync(Userid).Result.FirstName;
            var lName    = _context.Users.FindAsync(Userid).Result.LastName;
            var password = _context.Users.FindAsync(Userid).Result.PasswordHash;
            var features = _context.Users.FindAsync(Userid).Result.Features;
            var property = _context.Users.FindAsync(Userid).Result.PropertyType;

            if (requestStatus == RequestStatus.cancelled || requestStatus == RequestStatus.pending)
            {
                if (ModelState.IsValid && model.RequestStatus == RequestStatus.completed)
                {
                    var request = await _context.Request.FindAsync(id);

                    request.CustomerName      = FullName;
                    request.Address           = address;
                    request.PhoneNumber       = phone;
                    request.MembershipType    = _context.Request.FindAsync(id).Result.MembershipType;
                    request.RequestId         = _context.Request.FindAsync(id).Result.RequestId;
                    request.ServiceType       = _context.Request.FindAsync(id).Result.ServiceType;
                    request.ScheduleTime      = _context.Request.FindAsync(id).Result.ScheduleTime;
                    request.NeededService     = _context.Request.FindAsync(id).Result.NeededService;
                    request.Comment           = _context.Request.FindAsync(id).Result.Comment;
                    request.ApplicationUserId = Userid;
                    request.RefNo             = _context.Request.FindAsync(id).Result.RefNo;
                    //request.RequestStatus = _context.Request.Find(request.RequestStatus)

                    request.AdminComment       = model.AdminComment;
                    request.RequestStatus      = model.RequestStatus;
                    request.Cost               = model.Cost;
                    request.CostDetails        = model.CostDetails;
                    request.PhotoPath          = _context.Request.FindAsync(id).Result.PhotoPath;
                    request.VideoPath          = _context.Request.FindAsync(id).Result.VideoPath;
                    request.CancellationRemark = _context.Request.FindAsync(id).Result.CancellationRemark;
                    //request.ApplicationUserId = _context.Request.FindAsync(Request).Result.ApplicationUserId;



                    var profile = await _userManager.FindByIdAsync(request.ApplicationUserId);

                    //profile.Id = request.ApplicationUserId;
                    profile.CustomerName   = FullName;
                    profile.FirstName      = fName;
                    profile.LastName       = lName;
                    profile.Address        = address;
                    profile.PhoneNumber    = phone;
                    profile.Features       = features;
                    profile.PropertyType   = property;
                    profile.PasswordHash   = password;
                    profile.Membership     = membership;
                    profile.Email          = email;
                    profile.DateRegistered = date;
                    if (profile.Membership == MembershipType.SUB)
                    {
                        profile.MyBalance     = prevBal - model.Cost;
                        request.PaymentStatus = PaymentStatus.paid;
                    }
                    else
                    {
                        profile.MyBalance = prevBal;
                    }

                    _context.Update(request);
                    _context.Update(profile);
                    await _context.SaveChangesAsync();

                    var callbackUrl = Url.Action("Details", "UserRequest", new { id = request.RequestId },
                                                 protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(email, "Request Completed",
                                                    $"Dear " + profile.FirstName +
                                                    $" <br />" +
                                                    $" Your Request has been completed" +
                                                    $" <br />" +
                                                    $"click the button below to check the details and cost" +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{callbackUrl}'>Check My Request</a>" +
                                                    $" <br />" +
                                                    $" " +
                                                    $" <br />"
                                                    );

                    var admincallbackUrl = Url.Action("Edit", "Request", new { id = request.RequestId },
                                                      protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(adminEmail, "Request Completed",

                                                    $"  Request from  " + request.CustomerName +
                                                    $" has been completed" +
                                                    $" <br />" +
                                                    $"click the button below to check the details of the request" +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{admincallbackUrl}'>Check Request</a>" +
                                                    $" <br />" +
                                                    $" " +
                                                    $" <br />"
                                                    );


                    return(RedirectToAction("Index", new { id = request.RequestId }));
                }

                ModelState.AddModelError(string.Empty, "Please change Request Status to Completed and fill all fields ");
                return(View(model));
            }
            if (ModelState.IsValid)
            {
                var request = await _context.Request.FindAsync(id);

                request.CustomerName      = FullName;
                request.Address           = address;
                request.PhoneNumber       = phone;
                request.MembershipType    = _context.Request.FindAsync(id).Result.MembershipType;
                request.RequestId         = _context.Request.FindAsync(id).Result.RequestId;
                request.ServiceType       = _context.Request.FindAsync(id).Result.ServiceType;
                request.ScheduleTime      = _context.Request.FindAsync(id).Result.ScheduleTime;
                request.NeededService     = _context.Request.FindAsync(id).Result.NeededService;
                request.Comment           = _context.Request.FindAsync(id).Result.Comment;
                request.ApplicationUserId = Userid;
                request.RefNo             = _context.Request.FindAsync(id).Result.RefNo;
                request.PaymentStatus     = _context.Request.FindAsync(id).Result.PaymentStatus;
                //request.RequestStatus = _context.Request.Find(request.RequestStatus)

                request.AdminComment       = admin.AdminComment;
                request.RequestStatus      = _context.Request.FindAsync(id).Result.RequestStatus;
                request.Cost               = _context.Request.FindAsync(id).Result.Cost;
                request.CostDetails        = admin.CostDetails;
                request.PhotoPath          = _context.Request.FindAsync(id).Result.PhotoPath;
                request.VideoPath          = _context.Request.FindAsync(id).Result.VideoPath;
                request.CancellationRemark = _context.Request.FindAsync(id).Result.CancellationRemark;
                //request.ApplicationUserId = _context.Request.FindAsync(Request).Result.ApplicationUserId;



                var profile = await _userManager.FindByIdAsync(request.ApplicationUserId);

                //profile.Id = request.ApplicationUserId;
                profile.CustomerName   = FullName;
                profile.FirstName      = fName;
                profile.LastName       = lName;
                profile.Address        = address;
                profile.PhoneNumber    = phone;
                profile.Features       = features;
                profile.PropertyType   = property;
                profile.PasswordHash   = password;
                profile.Membership     = membership;
                profile.Email          = email;
                profile.DateRegistered = date;
                profile.MyBalance      = prevBal;


                _context.Update(request);
                _context.Update(profile);
                await _context.SaveChangesAsync();

                var callbackUrl = Url.Action("Details", "UserRequest", new { id = request.RequestId },
                                             protocol: HttpContext.Request.Scheme);
                await _emailSend.SendEmailAsync(email, "Request Details updated",
                                                $"Dear " + profile.FirstName +
                                                $" <br />" +
                                                $" Your Request details has been updated" +
                                                $" <br />" +
                                                $"click the button below to check the details and cost" +
                                                $" <br /> " +
                                                $" <br /> " +
                                                $" <br /> " +
                                                $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{callbackUrl}'>Check My Request</a>" +
                                                $" <br />" +
                                                $" " +
                                                $" <br />"
                                                );

                var admincallbackUrl = Url.Action("Edit", "Request", new { id = request.RequestId },
                                                  protocol: HttpContext.Request.Scheme);
                await _emailSend.SendEmailAsync(adminEmail, "Request Details Updated",

                                                $"  Request from  " + request.CustomerName +
                                                $"has been updated" +
                                                $" <br />" +
                                                $"click the button below to check the details of the request" +
                                                $" <br /> " +
                                                $" <br /> " +
                                                $" <br /> " +
                                                $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{admincallbackUrl}'>Check Request</a>" +
                                                $" <br />" +
                                                $" " +
                                                $" <br />"
                                                );


                return(RedirectToAction("Index", new { id = request.RequestId }));
            }
            return(View(admin));
        }
        public async Task <IActionResult> Create(CreateRequestViewModel model)

        {
            if (model.ScheduleTime > DateTime.Now)
            {
                if (ModelState.IsValid)
                {
                    var firstName = _userManager.GetUserAsync(User).Result.FirstName;
                    var lastName  = _userManager.GetUserAsync(User).Result.LastName;
                    var phone     = _userManager.GetUserAsync(User).Result.PhoneNumber;
                    var FullName  = firstName + " " + lastName;
                    //var FullName = "Akin Ishola";
                    var    address            = _userManager.GetUserAsync(User).Result.Address;
                    string imageFileName      = FirstImageUploadedFile(model);
                    var    id                 = _userManager.GetUserAsync(User).Result.Id;
                    var    membership         = _userManager.GetUserAsync(User).Result.Membership;
                    string firstVideoFileName = FirstVideoUploadedFile(model);
                    var    email              = _userManager.GetUserAsync(User).Result.Email;
                    var    admin              = "*****@*****.**";



                    Request newRequest = new Request
                    {
                        Address           = address,
                        PhoneNumber       = phone,
                        CustomerName      = FullName,
                        NeededService     = model.NeededService,
                        ServiceType       = model.ServiceType,
                        ScheduleTime      = model.ScheduleTime,
                        Comment           = model.Comment,
                        PhotoPath         = imageFileName,
                        ApplicationUserId = id,
                        MembershipType    = membership,
                        RequestStatus     = RequestStatus.pending,
                        RefNo             = model.RefNo,
                        MyService         = model.NeededService.ToString(),
                        VideoPath         = firstVideoFileName,
                        PaymentStatus     = PaymentStatus.unpaid
                    };
                    _context.Add(newRequest);
                    await _context.SaveChangesAsync();

                    var myid        = newRequest.RequestId;
                    var callbackUrl = Url.Action("Details", "UserRequest", new { id = newRequest.RequestId },
                                                 protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(email, "Request Successful",
                                                    $"Dear " + firstName +
                                                    $" <br />" +
                                                    $" Your Request has been created" +
                                                    $" <br />" +
                                                    $"we will contact you shortly " +
                                                    $"click the button below to check the details and status of your request" +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{callbackUrl}'>Check My Request</a>" +
                                                    $" <br />" +
                                                    $" " +
                                                    $" <br />"
                                                    );

                    var admincallbackUrl = Url.Action("Edit", "Request", new { id = newRequest.RequestId },
                                                      protocol: HttpContext.Request.Scheme);
                    await _emailSend.SendEmailAsync(admin, "New Request",

                                                    $" New Request has been created by " + FullName +
                                                    $" <br />" +
                                                    $"click the button below to check the details of the request" +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <br /> " +
                                                    $" <a style=\"  text-decoration: none; color: #fff; background: #101522; padding: 7px 22px; margin-right: 10px; border-radius: 50px; border: 2px solid #f82249;font-weight: 600; margin-left: 8px; margin-top: 2px; margin-bottom: 2px; line-height: 1.5;font-size: 13px;\" href ='{admincallbackUrl}'>Check Request</a>" +
                                                    $" <br />" +
                                                    $" " +
                                                    $" <br />"
                                                    );


                    return(RedirectToAction(nameof(Index)));
                    //return RedirectToAction("details", new { id = newRequest.RequestId });
                }
            }

            ModelState.AddModelError(string.Empty, "Scheduled Time Invalid! ");
            return(View(model));
        }