Esempio n. 1
0
        public HttpResponseMessage ForgotPassword(InsertTokenRequest model)
        {
            if (!ModelState.IsValid)
            {
                Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            bool success = false;

            ApplicationUser thisUser = UserService.GetUser(model.Email);

            UserDomain smsText = new UserDomain();

            smsText = _UserProfileService.GetPhoneNumberByEmail(model.Email);

            if (thisUser != null)
            {
                //- Create Token

                model.TokenType = Enums.TokenType.ForgotPassword;

                model.UserId = thisUser.Id;

                Guid token = _TokenService.RegisterToken(model);

                //- Create the link
                string link = "/public/resetpassword/" + token.ToString();

                link = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped) + link;

                //- Send Link to user email
                EmailRequest confirm = new EmailRequest();

                confirm.UserEmail = thisUser.Email;
                confirm.Subject   = "Reset Your Password";
                confirm.Content   = link;

                _UserEmailService.SendEmail(confirm);

                // TEXTING SERVICE BUILT BY RAVID YOEUN
                NotifySMSRequest userModel = new NotifySMSRequest();

                userModel.Phone     = smsText.PhoneNumber;
                userModel.firstName = smsText.FirstName;
                userModel.lastName  = smsText.LastName;
                userModel.url_link  = link;

                NotifySMSService.SendConfirmText(userModel);
                success = true;
            }

            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = success;

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 2
0
        public HttpResponseMessage CreateToken(InsertTokenRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            ItemResponse <Guid> response = new ItemResponse <Guid>();

            response.Item = _TokenService.RegisterToken(model);
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Esempio n. 3
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

        public EmailRequest BuildAccountConfirmEmail(InsertTokenRequest model)
        {
            string Token = _TokenService.RegisterToken(model).ToString();

            string ConfirmationUrl = String.Concat("http://quotemule.dev/Public/ConfirmAccount/", Token);

            string HelpDeskUrl = "https://help.market.quotemule.com";

            EmailRequest ToSend = new EmailRequest
            {
                UserEmail = model.Email,
                Subject   = "Confirm Your QuoteMule Account",
                Content   = String.Format("Hello,\n\nWelcome to QuoteMule!\n\nTo complete your registration, please click the link below:\n\n{0}\n\nIf you need help or have any questions, please visit {1}\n\nThanks!\n\nQuoteMule", ConfirmationUrl, HelpDeskUrl)
            };

            return(ToSend);
        }
Esempio n. 4
0
        // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        public void SendRegistrationConfirmationEmail(RegisterViewModel model, string userId)
        {
            InsertTokenRequest insertToken = new InsertTokenRequest
            {
                Email     = model.Email,
                UserId    = userId,
                TokenType = Enums.TokenType.Registration
            };

            EmailRequest ToSend = new EmailRequest();

            try
            {
                ToSend = BuildAccountConfirmEmail(insertToken);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            SendEmail(ToSend);
        }
        public HttpResponseMessage PostRegistration(InviteRegistrationRequest model)
        {
            IdentityUser newUserRegistration;

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            // When model is valid, CreateUser will post email and pw to database
            try
            {
                // creating a random password for the invited user
                string randomPassword = Guid.NewGuid().ToString();

                // setting the invited user's email and their password
                newUserRegistration = UserService.CreateUser(model.Email, randomPassword);

                //Instantiating a new blank profile
                CreateBlankProfileRequest newUserProfile = new CreateBlankProfileRequest();
                newUserProfile.UserEmail = model.Email;
                newUserProfile.CompanyId = model.CompanyId;
                newUserProfile.UserId    = newUserRegistration.Id;

                // Instantiating a new user role
                InsertNewUserRequest newUserRole = new InsertNewUserRequest();
                newUserRole.UserRole = model.UserRole;
                newUserRole.UserId   = newUserRegistration.Id;
                _UserProfileService.AddRoleToUser(newUserRole); //TODO: Confirm this method is not longer needed (K.H. advised he suspects code was changed to make this unecessary)

                // Inserting the Blank Profile data by calling on the UserService function for it.
                _UserProfileService.InsertBlankProfile(newUserProfile);
            }
            catch (IdentityResultException ex) // Display error code and message if user was not created
            {
                // var ExceptionError = new ErrorResponse("Failed to register new user. (server side)");

                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Result));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }

            // Insert new user's id into token table and generate new token
            string UserId = newUserRegistration.Id;

            // Pass new user's email and token into emailservice for activation link
            try
            {
                //- Pass the invite user's email data
                string NewUserEmail = newUserRegistration.Email;
                // Create inviteType token
                model.TokenType = Enums.TokenType.ForgotPassword;

                //- Instantiate a new token request
                InsertTokenRequest inviteUserToken = new InsertTokenRequest
                {
                    UserId    = newUserRegistration.Id,
                    Email     = model.Email,
                    TokenType = TokenType.ForgotPassword
                };
                //- Capturing user's information into the tokenRequest
                //inviteUserToken.UserId = newUserRegistration.Id;
                //inviteUserToken.Email = model.Email;
                //inviteUserToken.TokenType = TokenType.ForgotPassword;
                if (inviteUserToken.TokenType != 0)
                {
                    // Do something
                }

                Guid token = _TokenService.RegisterToken(inviteUserToken);

                //- Create the link for setting a new password
                string link = "/public/setpassword/" + token.ToString();

                //- Use HttpContext to generate a clickable link in the email
                link = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped) + link;
                // Call the service for the forgot password link
                //- Send Link to user email
                EmailRequest confirm = new EmailRequest();

                // Building the object's information
                confirm._email_link  = link;
                confirm._CompanyName = model.CompanyName;
                confirm.UserEmail    = newUserRegistration.Email;


                // sends user invitation via email and render HTML string
                // TemplateEmailService was created to render HTML pages to a string
                string renderedHTML = _TemplateEmailService.RazorViewToString("~/Views/Email_Template/Email_Template.cshtml", confirm);

                // Instantiating a new SendGridMessage
                SendGridMessage ActivateCrEmail = new SendGridMessage();
                ActivateCrEmail.AddTo(confirm.UserEmail);
                ActivateCrEmail.From = new MailAddress("*****@*****.**");
                // The Stringified HTML page is now converted by SendGridMessage with .Html
                ActivateCrEmail.Html    = renderedHTML;
                ActivateCrEmail.Subject = "You've been invited! Please set your password for your account.";

                // Instantiating the sendGridKey
                var sendGridKey = new SendGrid.Web(ConfigService.GetSendGridKey());

                // Delivering the email message
                sendGridKey.DeliverAsync(ActivateCrEmail);

                //UserEmailService useremailservice = new UserEmailService();

                //UserEmailService.SendEmail(confirm);
            }
            catch (NotImplementedException)
            {
                var ExceptionError = new ErrorResponse("Failed to send activation email to new user");

                return(Request.CreateResponse(HttpStatusCode.BadRequest, ExceptionError));
            }


            return(Request.CreateResponse(HttpStatusCode.OK, model));
        }
Esempio n. 6
0
        public HttpResponseMessage Register(UserAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            ItemResponse <bool> response = new ItemResponse <bool>();

            bool success = false;

            IdentityUser newUser = null;

            // Use model input to build user Account, company, and profile in DB
            try
            {
                // Create User Account
                newUser = UserService.CreateUser(model.Email, model.Password);

                // Determine company role
                CompanyRoleType companyType;
                switch (model.CompanyRole)
                {
                case "Buyer":
                    companyType = CompanyRoleType.Buyer;
                    break;

                case "Supplier":
                    companyType = CompanyRoleType.Supplier;
                    break;

                case "Shipper":
                    companyType = CompanyRoleType.Shipper;
                    break;

                default:
                    throw new Exception("Unrecognized Company Role: " + model.CompanyRole);
                }

                // Create Company Account
                CompanyInsertRequest company = new CompanyInsertRequest
                {
                    Name    = model.Company,
                    OwnerId = newUser.Id,
                    TypeId  = companyType
                };

                int companyId = _CompanyOptionService.InsertCompany(company);


                // Set User Role
                _AdminService.SetUserRole(newUser.Id, _AdminService.GetCompanyOwnerRoleId());

                //- Create Blank User Profile
                CreateBlankProfileRequest newUserProfile = new CreateBlankProfileRequest
                {
                    UserId    = newUser.Id,
                    UserEmail = newUser.Email,
                    CompanyId = companyId
                };

                _UserProfileService.InsertBlankProfile(newUserProfile);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (newUser != null)
            {
                // Use model input to create confirmation email
                InsertTokenRequest insertToken = new InsertTokenRequest
                {
                    Email     = model.Email,
                    UserId    = newUser.Id,
                    TokenType = Enums.TokenType.Registration
                };

                EmailRequest ToSend = new EmailRequest();
                try
                {
                    ToSend = _UserEmailService.BuildAccountConfirmEmail(insertToken);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                _UserEmailService.SendEmail(ToSend);

                success = true;
            }

            response.Item = success;

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }