Example #1
0
        public ResultStatus composeEmail(string from, List <string> to, string Body)
        {
            ResultStatus rs = new ResultStatus();

            try
            {
                MailMessage mail = new MailMessage();
                mail.From = new System.Net.Mail.MailAddress(from);

                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = System.Net.Mail.SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(from, "metalmorph")
                };

                smtp.Host = "smtp.gmail.com";

                smtp.EnableSsl = true;

                //recipient address
                foreach (string o in to)
                {
                    mail.To.Add(new MailAddress(o));
                }


                //Formatted mail body
                mail.IsBodyHtml = true;
                string st = Body.ToString();

                mail.Body = st;
                smtp.Send(mail);

                rs.SetSuccess("Reset password link has been sent!");
            }
            catch (Exception e)
            {
                rs.SetUnsuccess(e.Message);
            }
            return(rs);
        }
Example #2
0
        public ResultStatus InsertGeneratedCode(string Email, string GeneratedCode)
        {
            ResultStatus   rs     = new ResultStatus();
            ForgotPassword forgot = new ForgotPassword();

            try
            {
                forgot.Email         = Email;
                forgot.GeneratedCode = GeneratedCode;
                forgot.CreatedTime   = DateTime.Now;
                context.ForgotPassword.Add(forgot);
                context.SaveChanges();

                rs.SetSuccess("Code Generated Successfully");
            }
            catch (Exception e)
            {
                rs.SetUnsuccess(e.Message);
            }
            return(rs);
        }
Example #3
0
        public ResultStatus Login(LoginRequest param)
        {
            ResultStatus rs          = new ResultStatus();
            Password     encrypted   = new Password();
            string       newPassword = encrypted.Encrypt(param.Password);

            if (context.User.IsAuthentic(param.Username, newPassword))
            {
                HttpCookie authCookie               = FormsAuthentication.GetAuthCookie(param.Username, param.RememberMe);
                FormsAuthenticationTicket ticket    = FormsAuthentication.Decrypt(authCookie.Value);
                FormsAuthenticationTicket newTicket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, param.Username);
                authCookie.Value = FormsAuthentication.Encrypt(newTicket);
                response.Cookies.Add(authCookie);
                rs.SetSuccess("Success");
            }
            else
            {
                rs.SetUnsuccess("Failed");
            }
            return(rs);
        }