示例#1
0
        public async Task <JsonResult> Register(RegisterViewModel model)
        {
            try
            {
                var user = new User();

                #region Email Validity Check
                if (EmailProcess.IsValidEmail(model.Email) == false)
                {
                    return(Json(new JsonMessage {
                        HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz E-Mail Adresi. Lütfen Kontrol Edin."
                    }));
                }
                #endregion

                #region Password Validity Check
                var checkPassword = PasswordProcess.IsValidPassword(model.Password);
                if (checkPassword != null)
                {
                    return(Json(new JsonMessage {
                        HataMi = true, Baslik = "İşlem Başarısız", Mesaj = checkPassword
                    }));
                }
                if (model.Password != model.ReTypePassword)
                {
                    return(Json(new JsonMessage {
                        HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Lütfen Parola Bilgilerinizi Kontrol Edin."
                    }));
                }
                #endregion

                #region Default Picture Url Settings
                string defautPictureUrl = null;
                if (model.Gender == Constants.Gender.Male)
                {
                    defautPictureUrl = Constants.DefaultPictureUrl.DefaultPictureUrlMale;
                }
                if (model.Gender == Constants.Gender.Female)
                {
                    defautPictureUrl = Constants.DefaultPictureUrl.DefaultPictureUrlFemale;
                }
                #endregion

                #region Default User Type Settings
                var studentUserType = await _userTypeService.SingleOrDefaultAsync(x => x.Code == UserTypes.Student.GetHashCode());

                #endregion

                #region User Sistemde Var Mı Kontrolü
                user = await _userService.SingleOrDefaultAsync(x => x.Email == model.Email && x.Name.ToLower() == model.UserName.ToLower() && x.Surname.ToLower() == model.UserSurname.ToLower() && x.IsDeleted == false);

                if (user != null)
                {
                    return(Json(new JsonMessage {
                        HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Eklemek istediğiniz özelliklere sahip kullanıcı sistemde zaten mevcut."
                    }));
                }
                #endregion

                #region Kayıt İşlemi

                user = new User
                {
                    Name         = model.UserName,
                    Surname      = model.UserSurname,
                    Email        = model.Email,
                    Password     = PasswordProcess.HesaplaSHA256(model.Password),
                    RegisterDate = DateTime.Now,
                    IsDeleted    = false,
                    UserTypeId   = studentUserType.Id,
                    PictureUrl   = defautPictureUrl,
                    Gender       = model.Gender,
                };
                await _userService.AddAsync(user);

                #endregion

                return(Json(new JsonMessage {
                    HataMi = false, Baslik = "İşlem Başarılı", Mesaj = "Kayıt İşleminiz Başarıyla Gerçekleşti."
                }));
            }
            catch (Exception)
            {
                return(Json(new JsonMessage {
                    HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "İşlem Başarısız. Yöneticinize Başvurun."
                }));
            }
        }
        public async Task <JsonResult> UserLogin(LoginViewModel model)
        {
            #region Email Validity Check
            if (EmailProcess.IsValidEmail(model.UserMail) == false)
            {
                return(Json(new JsonMessage {
                    HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz E-Mail Adresi. Lütfen Kontrol Edin."
                }));
            }
            #endregion

            var password = PasswordProcess.HesaplaSHA256(model.UserPassword).ToLower();
            var user     = await _userService.SingleOrDefaultAsync(x => x.Email == model.UserMail && x.Password == password && x.IsDeleted == false);

            if (user != null)
            {
                #region Session Settings
                var userType = await _userTypeService.GetByIdAsync((int)user.UserTypeId);

                SessionManagement.ActiveUserNameSurname = user.Name + " " + user.Surname;
                SessionManagement.ActiveUserPictureUrl  = user.PictureUrl;
                SessionManagement.ActiveUserId          = user.Id;
                if (userType.Code == UserTypes.Admin.GetHashCode())
                {
                    HttpContext.Session.SetString("IsAdmin", userType.Name);
                    HttpContext.Session.GetString("IsAdmin");
                    SessionManagement.IsAdmin              = true;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.Student.GetHashCode())
                {
                    HttpContext.Session.SetString("IsStudent", userType.Name);
                    HttpContext.Session.GetString("IsStudent");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = true;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.JuryMember.GetHashCode())
                {
                    HttpContext.Session.SetString("IsJuryMember", userType.Name);
                    HttpContext.Session.GetString("IsJuryMember");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = true;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.Assistant.GetHashCode())
                {
                    HttpContext.Session.SetString("IsAssistant", userType.Name);
                    HttpContext.Session.GetString("IsAssistant");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = true;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.Instructor.GetHashCode())
                {
                    HttpContext.Session.SetString("IsInstructor", userType.Name);
                    HttpContext.Session.GetString("IsInstructor");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = true;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.Chair.GetHashCode())
                {
                    HttpContext.Session.SetString("IsChair", userType.Name);
                    HttpContext.Session.GetString("IsChair");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = true;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.Coordinator.GetHashCode())
                {
                    HttpContext.Session.SetString("IsCoordinator", userType.Name);
                    HttpContext.Session.GetString("IsCoordinator");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = true;
                    SessionManagement.IsExternalJuryMember = false;
                }
                if (userType.Code == UserTypes.ExternalJuryMember.GetHashCode())
                {
                    HttpContext.Session.SetString("IsExternalJuryMember", userType.Name);
                    HttpContext.Session.GetString("IsExternalJuryMember");
                    SessionManagement.IsAdmin              = false;
                    SessionManagement.IsStudent            = false;
                    SessionManagement.IsJuryMember         = false;
                    SessionManagement.IsAssistant          = false;
                    SessionManagement.IsInstructor         = false;
                    SessionManagement.IsChair              = false;
                    SessionManagement.IsCoordinator        = false;
                    SessionManagement.IsExternalJuryMember = true;
                }
                #endregion

                return(Json(new JsonMessage {
                    HataMi = false, Baslik = "İşlem Başarılı", Mesaj = "Sisteme Giriş İşlemi Başarıyla Gerçekleşti."
                }));
            }
            return(Json(new JsonMessage {
                HataMi = true, Baslik = "İşlem Başarısız", Mesaj = "Geçersiz Kullanıcı Adı veya Şifre"
            }));
        }