public ResultClassToken ChangePassword(ChangePasswordModel cP, string token) { ResultClassToken rc = new ResultClassToken(); using (LystenEntities db = new LystenEntities()) { var pwd = SecutiryServices.EncodePasswordToBase64(cP.CurrentPassword); var data = db.User_Master.Where(x => x.Password == pwd && x.Id == cP.UserId).FirstOrDefault(); if (data != null) { data.Password = SecutiryServices.EncodePasswordToBase64(cP.NewPassword); db.Entry(data).State = EntityState.Modified; db.SaveChanges(); rc.Code = (int)HttpStatusCode.OK; rc.Msg = ap.Success; //objresult.Data = model; } else { rc.Code = (int)HttpStatusCode.NotFound; rc.Msg = ap.CurrentPaasswordNotSame; //objresult.Data = model; } } return(rc); }
public async Task <String> SendEmail(string email) { String additionalProductDetails = string.Empty; using (LystenEntities db = new LystenEntities()) { var obj = db.User_Master.Where(x => x.Email == email).Select(x => x.Password).FirstOrDefault(); if (obj != null) { var PASS = SecutiryServices.DecodeFrom64(obj); es.SendUserForgotPassword(email, PASS); } } return(additionalProductDetails); }
public static bool SendEmail(string Email, string UserName, string Password) { using (LystenEntities db = new LystenEntities()) { try { var template = db.EmailTemplates.Where(x => x.SystemName == "system.account.verification").FirstOrDefault(); var emailaccount = db.EmailAccounts.FirstOrDefault(); var _password = SecutiryServices.DecodeFrom64(Password); MailMessage mailMsg = new MailMessage(); mailMsg.To.Add(new MailAddress(Email, "")); mailMsg.From = new MailAddress(emailaccount.EmailId, "Lysten"); //mailMsg.To.Add(new MailAddress(Email, "Mitaja Corp.")); //mailMsg.From = new MailAddress("*****@*****.**", "Mitaja Corp."); mailMsg.Subject = template.Subject; string body = template.Body; body = body.Replace("{Username}", UserName); body = body.Replace("{Password}", _password); mailMsg.IsBodyHtml = true; mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html)); SmtpClient smtpClient = new SmtpClient(emailaccount.SMTPRelay, Convert.ToInt32(emailaccount.Port)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(emailaccount.EmailId, emailaccount.Password); smtpClient.Credentials = credentials; smtpClient.EnableSsl = Convert.ToBoolean(emailaccount.EnableSSL); ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); }; smtpClient.Send(mailMsg); } catch (Exception ex) { throw ex; } } //try //{ // MailMessage mailMsg = new MailMessage(); // mailMsg.To.Add(new MailAddress(Email, UserName)); // mailMsg.From = new MailAddress("*****@*****.**", "Lysten"); // //mailMsg.To.Add(new MailAddress(Email, "Mitaja Corp.")); // //mailMsg.From = new MailAddress("*****@*****.**", "Mitaja Corp."); // mailMsg.Subject = "Account Verified"; // string body = ""; // body = "--> Thank you for registering as Service Provider with Lysten. Please login with your below credentials: <br/><br/>"; // body=body+ "<br/>UserName: "******"<br/>Password: "******"<br/>If you have any questions, please contact us xxxx @xx.com"; // body = body + "<br/>Registration confirmation email should be sent to the service provider once admin will approve the user from the admin panel."; // body = body + "<br/>Random password for the service provider should be generate and will pass in the email."; // mailMsg.IsBodyHtml = true; // mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(body, null, MediaTypeNames.Text.Html)); // SmtpClient smtpClient = new SmtpClient("*****@*****.**", 465); // System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "Testing.Mitaja1"); // smtpClient.Credentials = credentials; // smtpClient.EnableSsl = true; // ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) // { return true; }; // smtpClient.Send(mailMsg); //} //catch //{ //} return(true); }
public async Task <ResultClass> newRegisterUser(User_Master um) { using (LystenEntities db = new LystenEntities()) { if (string.IsNullOrEmpty(um.Password)) { um.Password = um.UserName + "@2018"; } var pwd = SecutiryServices.EncodePasswordToBase64(um.Password); var result = (from um23 in db.User_Master where um23.Email.ToUpper() == um.Email.ToUpper() && um23.Password == pwd select um23 ).FirstOrDefault(); um.Password = pwd; var model = new { }; if (result != null) { objresult.Code = (int)HttpStatusCode.Found; objresult.Msg = ap.UserEMailExist; objresult.Data = model; } else { if (db.User_Master.Any(x => x.UserName.ToLower().Trim() == um.UserName.ToLower().Trim())) { objresult.Code = (int)HttpStatusCode.Found; objresult.Msg = ap.UserNameExist; objresult.Data = model; (objresult.AccessToken) = ""; return(objresult); } um.Displayname = um.FullName; um.DeviceType = um.DeviceType; um.IsLogin = true; um.IsDisclaimer = false; um.RoleId = um.RoleId; um.PostalCode = um.PostalCode; um.Skill = um.Skill; um.SSN = um.SSN; um.IsVerified = false; um.DateOfBirth = um.DateOfBirth; um.TimeZone = um.TimeZone; um.Address = um.Address; um.CityId = um.CityId; um.StateId = um.StateId; um.CountryId = um.CountryId; db.User_Master.Add(um); db.SaveChanges(); objresult.Code = (int)HttpStatusCode.OK; objresult.Msg = ap.Success; objresult.Data = AutoMapper.Mapper.Map <UserViewModel>(um); objresult.Data.Favourite = new List <ProfileFavourite>() { }; } (objresult.AccessToken) = ""; if (objresult.Code == (int)HttpStatusCode.OK) { TokenDetails objToken = await generatToken(um.Email, um.Password, um.DeviceToken); (objresult.AccessToken) = objToken.access_token; var obj = AutoMapper.Mapper.Map <UserViewModel>(objresult.Data); Add_UpdateToken(obj.Id, objToken, 1, um.DeviceType); } return(objresult); } }
public async Task <ResultClass> PostLoginAuthenticationAsync(UserMasterModel objtblusermaster) { try { using (LystenEntities db = new LystenEntities()) { string baseURL = HttpContext.Current.Request.Url.Authority; baseURL += (WebConfigurationManager.AppSettings["userimagepath"]).Replace("~", ""); //db.Configuration.LazyLoadingEnabled = false; var pwd = SecutiryServices.EncodePasswordToBase64(objtblusermaster.Password); User_Master result = (from um23 in db.User_Master where um23.Email.ToUpper() == objtblusermaster.UserNameorEmail.ToUpper() && um23.Password == pwd select um23 ).FirstOrDefault(); if (result == null) { result = (from um23 in db.User_Master where um23.UserName.ToUpper() == objtblusermaster.UserNameorEmail.ToUpper() && um23.Password == pwd select um23 ).FirstOrDefault(); } var model = new { }; if (result != null) { var id = result.Id; if (result.IsActive == true) { objresult.Code = (int)HttpStatusCode.OK; objresult.Msg = ap.Success; //var user = result; objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result); User_Master obj = result;//db.User_Master.Where(x => x.Id == id).FirstOrDefault(); obj.SessionId = null; obj.IsLogin = true; obj.DeviceType = objtblusermaster.DeviceType; obj.DeviceToken = objtblusermaster.DeviceToken; obj.TimeZone = objtblusermaster.TimeZone; db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); objresult.Data.Image = US.GetFavouriteImage(baseURL, result.Id); } else { objresult.Code = (int)HttpStatusCode.Accepted; objresult.Msg = ap.LoginUserIsNotActive; //var user = result; objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result); } } else if (result == null) { objresult.Code = (int)HttpStatusCode.NotFound; objresult.Msg = ap.LoginUserInvalid; objresult.Data = model; objresult.AccessToken = ""; } else { objresult.Code = (int)HttpStatusCode.Accepted; objresult.Msg = ap.LoginUserIsNotActive; result.Image = US.GetFavouriteImage(baseURL, result.Id); objresult.Data = AutoMapper.Mapper.Map <UserViewLoginModel>(result); } if (objresult.Code == (int)HttpStatusCode.OK) { TokenDetails objToken = await generatToken((result.Email), (result.Password), (result.DeviceToken)); //User_Master obj1 = db.User_Master.Where(x => x.Id == result.Id).FirstOrDefault(); //obj1.DeviceType = objtblusermaster.DeviceType; ////obj.DeviceToken = objtblusermaster.DeviceToken; //db.Entry(obj1).State = EntityState.Modified; //db.SaveChanges(); (objresult.AccessToken) = objToken.access_token; var obj = objresult.Data as UserViewLoginModel; Add_UpdateToken(obj.Id, objToken, 1, objtblusermaster.DeviceType); } //if (updatetoken) //{ // (objresult.Data as UserViewModel).AccessToken = accessToken; //} //else //{ // (objresult.Data as UserViewModel).AccessToken = ""; //} //db.Configuration.LazyLoadingEnabled = true; return(objresult); } } catch (Exception ex) { objresult.Code = (int)HttpStatusCode.NotAcceptable; objresult.Msg = Convert.ToString(ex.Message); objresult.Data = ""; objresult.AccessToken = ""; return(objresult); } }