Пример #1
0
        public HttpResponseMessage send(EmailInsertRequest model)
        {
            if (!ModelState.IsValid || model == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            EmailInsertRequest response = new EmailInsertRequest();

            response = MailServices.send(model);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #2
0
        public static dynamic send(EmailInsertRequest model)
        {
            Email from1 = new Email(model.from);

            string subject1 = model.subject;

            Content content1 = new Content("text/html", model.content);

            Execute(from1, subject1, content1).Wait();

            return(model);
        }
Пример #3
0
        public static void AdminResetEmailPassword(EmailInsertRequest model, Guid tokenId)
        {
            SendGridMessage resetUserPassword = new SendGridMessage();                                                                                               //An object is created with datatype 'SendGridMessage' which is class that enable us to send out the pw reset email to user.

            resetUserPassword.AddTo(model.Email);                                                                                                                    //User email.
            resetUserPassword.From    = new MailAddress(ConfigService.AdminEmail);                                                                                   //Send from the admin (right now it is under Jimmy).
            resetUserPassword.Subject = "Reset Your PW";                                                                                                             //Title of the email.
            resetUserPassword.Text    = "Forgot Your Password? Follow this cool link to reset your pw: " + ConfigService.BaseUrlLink + "/password/reset/" + tokenId; //Content (link) in email.

            // Create a Web transport, using API Key
            var transportWeb = new SendGrid.Web(ConfigService.SendGridApiKey);

            // Send the email.
            transportWeb.DeliverAsync(resetUserPassword);
        }
Пример #4
0
        public HttpResponseMessage post(EmailInsertRequest model)
        {
            if (!ModelState.IsValid)                                                    //if model request is invalid, it will return a bad request.
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (UserService.IsUser(model.Email))                                        //a function that checks if this person enters in their email is an actual user (actual email when signed up).
            {
                ApplicationUser currentUser = UserService.GetUser(model.Email);         //a function that gets the userId through email.

                Guid tokenId = TokenService.Post(currentUser.Id);                       //generate a unique token for the user pw reset request.

                ContactEmailService.AdminResetEmailPassword(model, tokenId);            //calling the function from the ContactEmailService class that includes the 'emailInsertRequest model'.

                ItemResponse <Guid> response = new ItemResponse <Guid>();               //Wrap up the 'Guid' in an envelope(which is the item response).
                response.Item = tokenId;                                                //'ItemReponse' gives structure to the json which gets passed back to the user.
                return(Request.CreateResponse(HttpStatusCode.OK, response));            //Return the tokenId to the user.
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No account exist"));
            }
        }