/// <summary> /// /// </summary> /// <param name="username">ini sebenarnya username OR NIK</param> /// <param name="password"></param> /// <returns></returns> public override bool ValidateUser(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(false); } using (ModelAsmRemote _db = new ModelAsmRemote()) { //var user = (from _usr in _db.ms_user // where string.Compare(username, _usr.user_name, StringComparison.OrdinalIgnoreCase) == 0 // && string.Compare(password, _usr.user_password, StringComparison.OrdinalIgnoreCase) == 0 // && _usr.fl_active == true // && _usr.deleted_date == null // select _usr).FirstOrDefault(); //sesuai request user : bisa userid atau nik //date: 2019-08-24 var user = (from _usr in _db.ms_user join _emp in _db.ms_employee on _usr.employee_id equals _emp.employee_id where (string.Compare(username, _usr.user_name, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(username, _emp.employee_nik, StringComparison.OrdinalIgnoreCase) == 0) && string.Compare(password, _usr.user_password, StringComparison.OrdinalIgnoreCase) == 0 && _usr.fl_active == true && _usr.deleted_date == null select _usr).FirstOrDefault(); return((user != null) ? true : false); } }
public override string GetUserNameByEmail(string email) { using (ModelAsmRemote dbContext = new ModelAsmRemote()) { string username = (from u in dbContext.ms_user where string.Compare(email, u.ms_employee.employee_email) == 0 select u.user_name).FirstOrDefault(); return(!string.IsNullOrEmpty(username) ? username : string.Empty); } }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <returns></returns> public override string[] GetRolesForUser(string username) { if (!HttpContext.Current.User.Identity.IsAuthenticated) { return(null); } var userRoles = new string[] { }; using (ModelAsmRemote _db = new ModelAsmRemote()) { var selectedUser = (from usr in _db.ms_user.Include("ms_employee").Include("ms_employee_detail").Include("job_level_id") where string.Compare(usr.user_name, username, StringComparison.OrdinalIgnoreCase) == 0 && usr.deleted_date == null && usr.fl_active == true select usr //select new User //{ // user_id = usr.user_id, // user_name = usr.user_name, // user_password = usr.user_password, // employee_id = usr.ms_employee.employee_id, // employee_name = usr.ms_employee.employee_name, // employee_email = usr.ms_employee.employee_email, // fl_active = (bool)usr.fl_active , // Roles = usr.ms_employee.ms_employee_detail.user.Select( r => r.user_type_id) //} ).FirstOrDefault(); if (selectedUser != null) { //userRoles = new[] { selectedUser.ms_employee_detail.Select(r=>r.ms_job_level.job_level_code).ToString() }; userRoles = new[] { selectedUser.ms_user_type.user_type_code }; } return(userRoles.ToArray()); } }
public override MembershipUser GetUser(object loginview, bool userIsOnline) { using (ModelAsmRemote _db = new ModelAsmRemote()) { AccountLoginViewModel accountloginview = loginview as AccountLoginViewModel; User _user = new User(); //yang diambil dari login form string m_username = accountloginview.UserName; int m_company_id = accountloginview.company_id; int m_location_reg = accountloginview.asset_reg_location_id; int m_user_type_id = accountloginview.user_type_id; try { //var user = (from _usr in _db.ms_user // where string.Compare(m_username, _usr.user_name, StringComparison.OrdinalIgnoreCase) == 0 // && _usr.fl_active == true // && _usr.deleted_date == null // join _empdetail in _db.ms_employee_detail on _usr.employee_id equals _empdetail.employee_id // where _empdetail.company_id == m_company_id && _empdetail.asset_reg_location_id == m_location_reg && _empdetail.user_type_id == m_user_type_id // select _usr).FirstOrDefault(); var m_found_user = ( //from _usr in _db.ms_user //join _emp in _db.ms_employee on _usr.employee_id equals _emp.employee_id //where //(string.Compare(m_username, _usr.user_name, StringComparison.OrdinalIgnoreCase) == 0 //|| string.Compare(m_username, _emp.employee_nik, StringComparison.OrdinalIgnoreCase) == 0) //&& _user.user_type_id == m_user_type_id //&& _usr.fl_active == true //&& _usr.deleted_date == null //join _empdetail in _db.ms_employee_detail on _emp.employee_id equals _empdetail.employee_id //where _empdetail.company_id == m_company_id //&& _empdetail.asset_reg_location_id == m_location_reg from _usr in _db.ms_user join _emp in _db.ms_employee on _usr.employee_id equals _emp.employee_id where _usr.user_type_id == m_user_type_id && _usr.fl_active == true && _usr.deleted_date == null && (string.Compare(m_username, _usr.user_name, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(m_username, _emp.employee_nik, StringComparison.OrdinalIgnoreCase) == 0) join _empdetail in _db.ms_employee_detail on _emp.employee_id equals _empdetail.employee_id where _empdetail.company_id == m_company_id && _empdetail.location_id == m_location_reg //&& _empdetail.user_type_id == m_user_type_id //ambil dari form jangan dari tbl ini select _usr).FirstOrDefault(); if (m_found_user == null) { return(null); } //var selectedUser = new CustomMembershipUser(user); _user = new User { user_id = m_found_user.user_id, user_name = m_found_user.user_name, user_password = m_found_user.user_password, //user_type_id = user.user_type_id, /* kalo ambil dari table user */ user_type_id = m_user_type_id, /* ambil dari form login */ employee_id = m_found_user.employee_id, employee_nik = m_found_user.ms_employee.employee_nik, employee_name = m_found_user.ms_employee.employee_name, employee_email = m_found_user.ms_employee.employee_email, fl_active = (bool)m_found_user.fl_active //Roles = user.ms_employee.ms_employee_detail.Select(r => new Role //{ // RoleId = r.ms_user_type.user_type_id, // RoleCode = r.ms_user_type.user_type_code, // RoleName = r.ms_user_type.user_type_name //}).ToList<Role>() }; //var _objRoles = _db.ms_employee_detail.Include("job_level_id").Include("user_type_id").Where(e => e.employee_id == user.employee_id).Select(r => new Role //{ // RoleId = (r.user_type_id.HasValue) ? r.ms_user_type.user_type_id : 0, // RoleCode = (r.user_type_id.HasValue) ? r.ms_user_type.user_type_code : "GST", // RoleName = (r.user_type_id.HasValue) ? r.ms_user_type.user_type_name : "Guest" //}).ToList<Role>(); var _objRoles = _db.ms_employee_detail.Include("job_level_id") .Where(e => e.employee_id == m_found_user.employee_id && e.company_id == m_company_id && e.asset_reg_location_id == m_location_reg //&& e.user_type_id == m_user_type_id ).Select(r => new Role { RoleId = (r.job_level_id.HasValue) ? r.ms_job_level.job_level_id : 0, RoleCode = (r.job_level_id.HasValue) ? r.ms_job_level.job_level_code : "GST", RoleName = (r.job_level_id.HasValue) ? r.ms_job_level.job_level_name : "Guest" }).ToList <Role>(); if (_objRoles != null) { _user.Roles = new List <Role>(); foreach (Role _rlItem in _objRoles) { _user.Roles.Add(_rlItem); } } else { _user.Roles = new List <Role>(); } } catch (Exception _exc) { App_Helpers.app_logwriter.ToLog("CustomeMembership.GetUser():" + _exc.Message); //throw new Exception("GetUser():" + _exc.Message); } var selectedUser = new CustomMembershipUser(_user); return(selectedUser); } }
public Boolean Send() { Boolean returnBool = true; this.PopulateEmailAddress(); EmailSenderUserToken user_token = null; if (this.MAIL_SendMailAsync) { user_token = new EmailSenderUserToken(); } SmtpClient smtp_client = null; MailMessage mail_message = new MailMessage(); //string exMessage = ""; try { if (m_mail_port != 0) { smtp_client = new SmtpClient(m_mail_server, m_mail_port); } else { smtp_client = new SmtpClient(m_mail_server); } smtp_client.EnableSsl = this.MAIL_EnabledSSL; smtp_client.UseDefaultCredentials = this.MAIL_UseDefaultCredentials; smtp_client.Credentials = this.SetCredential(); mail_message.From = this.FromMailAddress; if (this.ToMailAddress.Count > 0) { foreach (MailAddress _emailAddress in this.ToMailAddress) { mail_message.To.Add(_emailAddress); } } if (this.ReplyToMailAddress.Count > 0) { foreach (MailAddress _emailAddress in this.ReplyToMailAddress) { mail_message.ReplyToList.Add(_emailAddress); } } if (this.CcMailAddress.Count > 0) { foreach (MailAddress _emailAddress in this.ToMailAddress) { mail_message.CC.Add(_emailAddress); } } if (this.BccMailAddress.Count > 0) { foreach (MailAddress _emailAddress in this.ToMailAddress) { mail_message.Bcc.Add(_emailAddress); } } if (this.HasAttachment) { foreach (string str_file in this.AttachmentFiles) { mail_message.Attachments.Add(new System.Net.Mail.Attachment(str_file)); } } mail_message.Subject = this.MailSubject; mail_message.Body = this.MailBody; mail_message.IsBodyHtml = true; smtp_client.DeliveryMethod = SmtpDeliveryMethod.Network; if (this.MAIL_SendMailAsync) { smtp_client.SendAsync(mail_message, user_token); user_token.MessageID = this.MessageId; user_token.SendResult = returnBool; user_token.SendResultMessage = "Sucess"; } else { smtp_client.Send(mail_message); } } catch (Exception mail_ex) { string exMessage = "Fail on EmailHelper.Send():" + mail_ex.Message.ToString(); m_error_message.Add(exMessage); returnBool = false; if (this.MAIL_SendMailAsync) { user_token.SendResult = returnBool; user_token.SendResultMessage = exMessage; } //throw mail_ex; } finally { m_mail_sent_time = DateTime.Now; try { using (ModelAsmRemote db = new ModelAsmRemote()) { string exMessage = ""; foreach (string str in this.m_error_message) { exMessage += str + Environment.NewLine; } sy_email_log sy_email_log = new sy_email_log() { elog_template = this.Email_Template, elog_from = this.FromAddress, elog_to = this.ToAddress, elog_cc = this.CcAddress, elog_bcc = this.BccAddress, elog_subject = this.MailSubject, elog_body = this.MailBody, elog_has_attachment = false, //elog_file_attachment = null, fl_active = true, created_date = m_mail_init_time, created_by = ((USER_PROFILE)System.Web.HttpContext.Current.Session["USER_PROFILE"]).UserId, fl_sent = returnBool, sent_date = m_mail_sent_time, err_message = exMessage }; sy_email_log = db.sy_email_log.Add(sy_email_log); db.SaveChanges(); }; } catch { } } return(returnBool); }
public ActionResult Registration(AccountRegistrationViewModel registrationView) { bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Email Verification string userName = Membership.GetUserNameByEmail(registrationView.employee_email); if (!string.IsNullOrEmpty(userName)) { ModelState.AddModelError("Warning Email", "Sorry: Email already Exists"); return(View(registrationView)); } //Save User Data using (ModelAsmRemote _db = new ModelAsmRemote()) { //var user = new User() //{ // Username = registrationView.Username, // FirstName = registrationView.FirstName, // LastName = registrationView.LastName, // Email = registrationView.Email, // Password = registrationView.Password, // ActivationCode = Guid.NewGuid(), //}; //dbContext.Users.Add(user); var emp = new ms_employee() { employee_email = registrationView.employee_email, employee_nik = registrationView.employee_nik, employee_name = registrationView.employee_name, fl_active = true, created_by = UserProfile.UserId, created_date = DateTime.Now, updated_by = UserProfile.UserId, updated_date = DateTime.Now, deleted_by = null, deleted_date = null, org_id = UserProfile.OrgId }; emp = _db.ms_employee.Add(emp); //int emp_id = emp.employee_id; var user = new ms_user() { user_name = registrationView.user_name, user_password = App_Helpers.CryptorHelper.Encrypt(registrationView.user_password, "MD5", true), employee_id = emp.employee_id, fl_active = true, created_by = UserProfile.UserId, created_date = DateTime.Now, updated_by = UserProfile.UserId, updated_date = DateTime.Now, deleted_by = null, deleted_date = null, org_id = UserProfile.OrgId }; _db.ms_user.Add(user); _db.SaveChanges(); } //Verification Email: //TIDAK usah aktifkan by email -> admin saja yanag mengaktifkan sendiri krna hrus pilih role, job title dan company //VerificationEmail(registrationView.Email, registrationView.ActivationCode.ToString()); messageRegistration = "Your account has been created successfully. ^_^"; statusRegistration = true; } else { messageRegistration = "Something Wrong!"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }